search
HomeBackend DevelopmentPHP TutorialWeibo Application--Ark Ticket

Weibo mini application

2012, the legendary doomsday, whether it’s true or not, I have a ticket to Noah’s Ark anyway…

Onlooker: http://endworld.sinaapp.com

—————————— -

This is a small application based on sae written by learning the authorization mechanism of Weibo. It uses a lot of GD functions

Now let’s make a simple learning summary

1. First create an application and apply for appkey

Sina Weibo: http://open.weibo.com

Tencent Community: http://opensns.qq.com

Tencent Weibo: http://open.t.qq.com

2. After creating the application, we next download the relevant sdk. Here we only use php as an example. The comments have been clearly written

Sina Weibo profile:

Tencent sdk: The Mahuateng thing is very painful, please download the file directly, all have comments

3. The most important thing for a good application is creativity, use your imagination
Ark The boat ticket is an imitation with no new ideas, so here is a brief introduction.
① First fill in the applied appid and appkey in congfig.php or appkey.php, and then configure the callback address.
② Obtain user information, according to the user information , use PHP's gd library to generate corresponding images. Things to note when generating images are: if the user has not customized the avatar, the avatar type is png, otherwise it is jpg. If it is a zombie user, the image and nickname may not be obtained.
③ When Sina's application is not online, that is, when it fails to pass the review, only the developer's account can use the application. Other user tests can only add test users in the application management background first, and only those with more than 10 test users have a chance to pass the review. This is It’s quite a pain in the butt, but it’s still easy to pass the review
⑤ Other users can use Tencent’s application normally even if it’s not online, but it’s more difficult to pass the review. Try not to use non-theme words in the application
4. Ark Ticket File Description
index.php homepage login button placement page
ticket-hall.php Weibo callback page, guides users to start using
ticket.php generates content to prepare for sending to Weibo
toweibo.php submits data to Weibo
suc.php informs the user of success

sdk download: http://helong.org/download001/weibosdk.7z


Ark Ferry Ticket Source Code: http://helong.org/download001/endworld.7z

@王香宇children’s shoes question, here is the explanation:

The program involves storage and other features in SAE, so it is only applicable to sae... Cannot be used directly in ordinary space...


index.php line 31 header('Location: http://endworld.sinaapp.com/qticket-hall.php'); This is the Weibo callback address

qticket.php lines 16 and 141 can be modified to relative paths. In the same way, the pictures involved can be modified to relative paths. My personal code has a bad personality and writes absolute paths

ticket.php imagejpeg($im ,SAE_TMP_PATH.'linshi.jpg',100);//Reading and writing method: save as a temporary file, here SAE_TMP_PATH is a temporary file in SAE

ticket.php line 156 $s->upload('2012',$userid. '.jpg',SAE_TMP_PATH.'linshi.jpg');//SAEstorage is used here, see http://apidoc.sinaapp.com/sae/SaeStorage.html#upload

If there is anything that needs improvement, please feel free to share it with us

  1. session_start();
  2. include_once( 'config.php' );
  3. include_once( 'saetv2.ex.class.php' );
  4. $c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION ['token']['access_token'] );
  5. /////////////
  6. //After OAuth authorization, get the UID of the authorized user
  7. $uid_get = $c->get_uid();
  8. $uid = $uid_get['uid'];
  9. $user_message = $c->show_user_by_id( $uid);//Get user and other basic information based on ID
  10. //////////// ///////////
  11. //Get the list of Weibo information posted by the user
  12. //user_timeline_by_id($uid,$page = 1,$count = 50,$since_id = 0,$max_id = 0, $feature = 0,$trim_user = 0,$base_app = 0)
  13. //$page: Page number
  14. ///$count: The maximum number of records returned each time, up to 200 records are returned, and the default is 50.
  15. //$uid: Specify the user UID or Weibo nickname
  16. //$since_id: If this parameter is specified, only Weibo messages with IDs larger than since_id (that is, Weibo messages published later than since_id) will be returned. Optional.
  17. //$max_id: If this parameter is specified, the Weibo messages mentioning the currently logged in user with an ID less than or equal to max_id will be returned. Optional.
  18. //$base_app: Whether to obtain data based on the current application. 1 means restricting Weibo in this application, 0 means no restrictions. Default is 0.
  19. //$feature: Filter type ID, 0: all, 1: original, 2: pictures, 3: video, 4: music, the default is 0.
  20. //$trim_user: Switch of user information in the return value, 0: Return complete user information, 1: User field only returns uid, default is 0.
  21. $ms = $c->user_timeline_by_id($uid); // done
  22. ///////////////////
  23. //Get the list of Weibo information posted by the user
  24. //user_timeline_by_name ($screen_name,$page = 1,$count = 50,$since_id = 0,$max_id = 0,$feature = 0,$trim_user = 0,$base_app = 0)
  25. //$screen_name: Weibo Nickname is mainly used to distinguish the user UID from the Weibo nickname. When the two are the same and there is ambiguity, it is recommended to use this parameter
  26. ?>
  27. Sina Weibo V2 interface demonstration program- Powered by Sina App Engine
  28. =$user_message['screen_name']?>,Hello!
  29. Send new Weibo

  30. ///////////////
  31. //Post a WeChat Bo information.
  32. //update ($status, $lat latitude, $long longitude, $annotations facilitate third parties to record data such as array("a"=>"b", "c"=>"d")) )
  33. if ( isset($_REQUEST['text']) ) {
  34. $ret = $c->update( $_REQUEST['text'] ); //Send Weibo
  35. if ( isset($ret['error_code'] ) && $ret['error_code'] > 0 ) {
  36. echo "

    Sending failed, error: {$ret['error_code']}:{$ret['error']}

    ";
  37. } else {
  38. echo "

    Sent successfully

    ";
  39. }
  40. }
  41. //////////////////////// //
  42. echo "
    ------Post pictures on Weibo----------
    ";
  43. //Post pictures on Weibo, pictures// $status: Weibo information to be updated. The information content does not exceed 140 Chinese characters, and a 400 error is returned if it is empty.
  44. //$pic_path: The path of the picture to be published, supports url. Only png/jpg/gif formats are supported.
  45. //$lat: latitude, the geographical location of the current Weibo post, the valid range is -90.0 to +90.0, + means northern latitude. Optional.
  46. //$long: Optional parameter, longitude. The valid range is -180.0 to +180.0, + represents east longitude.Optional
  47. $status='Publish picture on Weibo test April 23, 2012 14:25:43';
  48. $pic_path='http://www.baidu.com/img/baidu_sylogo1.gif';
  49. $ ret13 = $c->upload($status,$pic_path,$lat,$long);
  50. if( isset($ret13['error_code']) && $ret13['error_code'] > 0 ) {
  51. echo "

    Failed to post pictures on Weibo, error: {$ret7['error_code']}:{$ret7['error']}

    ";
  52. } else {
  53. echo "

    Successfully posted pictures on Weibo

    ";
  54. }
  55. /////////////////////
  56. echo "
    -------- Follow user--------
    ";
  57. //Follow user
  58. //Follow according to uid: follow_by_id ($uid)
  59. $ret2 = $c->follow_by_name('tohelong');
  60. if ( isset($ret2['error_code']) && $ret2['error_code'] > 0 ) {
  61. echo "

    Follow failed, error: {$ret2['error_code']}:{$ret2 ['error']}

    ";
  62. } else {
  63. echo "

    Follow Success

    ";
  64. }
  65. ////////////// //
  66. //Add a new user tag for the currently logged in user
  67. echo "
    ---------Add tag-------
    ";
  68. $ret6 = $ c->add_tags("tag2,tag3,tag4,tag test");;
  69. if( isset($ret6['error_code']) && $ret6['error_code'] > 0 ) {
  70. echo "Failed to add tag, error: {$ret6['error_code']}:{$ret6['error']}";
  71. } else {
  72. echo "

    Add tag successfully";

  73. }
  74. ////////////////////////
  75. echo "
    --------Collect a tweet Blog--------
    ";
  76. //Collect a Weibo message
  77. $sid='3437771555685532';
  78. $ret7 = $c->add_to_favorites ($sid);//$sid =Collected Weibo ID
  79. if( isset($ret7['error_code']) && $ret7['error_code'] > 0 ) {
  80. echo "

    Failed to collect, error: {$ret7['error_code ']}:{$ret7['error']}

    ";
  81. } else {
  82. echo "

    Collection successful

    ";
  83. }
  84. ////// /////////////////
  85. echo "
    --------Mutual fan list--------
    ";
  86. //Mutual fan list
  87. $ret8 = $c-> bilateral ($uid,1,50,0);
  88. //print_r($ret8);
  89. echo $ret8['users'][0]['location '];
  90. ///////////////////////
  91. echo "
    -------expression---------
    ";
  92. $ret9 = $c->emotions ($type = "face",$language = "cnname");
  93. //"face": normal expression, "ani": magic expression," cartoon":animation expression
  94. //print_r($ret9);
  95. echo "Weibo Application--Ark Ticket";
  96. ///////// /////////////
  97. echo "
    --------Comment on Weibo--------
    ";
  98. //Reply to one Comment on Weibo
  99. $id='3437771555685532';//Post id
  100. $comment='Comment test test';
  101. $ret10 = $c->send_comment($id,$comment,$comment_ori=0);
  102. //$comment_ori: When a comment is forwarded to Weibo, whether to comment to the original Weibo, 0: no, 1: yes, the default is 0
  103. if( isset($ret10['error_code']) && $ret10['error_code'] > 0 ) {
  104. echo "

    Comment failed, error: {$ret7['error_code']}:{$ret7['error']}

    ";
  105. } else {
  106. echo "

    Comment successful

    ";
  107. }
  108. //////////////////////
  109. echo "
    ------ --Get Weibo and author based on post id--------
    ";
  110. //Get a single Weibo information content based on ID
  111. $id='3437771555685532';//Post id
  112. $ret11 = $c->show_status ($id);
  113. //print_r($ret11);
  114. echo $ret11['text'];
  115. echo $ret11['user']['screen_name'];
  116. echo $ret11 ['user']['location'];
  117. ////////////////////
  118. echo "
    -------Username id Get information and Weibo---------
    ";
  119. //Get user information based on user UID or nickname. Also returns the latest Weibo.
  120. //show_user_by_name ($screen_name)
  121. $ret12 = $c->show_user_by_id($uid);
  122. //print_r($ret12);
  123. echo $ret12['screen_name'];
  124. echo "Weibo Application--Ark Ticket";
  125. echo $ret12['status']['text'];
  126. //////////////////// /
  127. echo "
    ----------------
    ";
  128. ?>
  129. =$item['id'];?> =$item['text'];?>=$item['source'];?>
  • Copy code


    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

    What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

    PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

    PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

    PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

    PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

    PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

    PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

    Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

    PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

    PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

    PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

    PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

    PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

    How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

    PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools