Home Backend Development PHP Tutorial Weibo Application--Ark Ticket

Weibo Application--Ark Ticket

Jul 25, 2016 am 09:07 AM

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. ,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<5M
  44. // $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.
  45. //$pic_path: The path of the picture to be published, supports url. Only png/jpg/gif formats are supported.
  46. //$lat: latitude, the geographical location of the current Weibo post, the valid range is -90.0 to +90.0, + means northern latitude. Optional.
  47. //$long: Optional parameter, longitude. The valid range is -180.0 to +180.0, + represents east longitude.Optional
  48. $status='Publish picture on Weibo test April 23, 2012 14:25:43';
  49. $pic_path='http://www.baidu.com/img/baidu_sylogo1.gif';
  50. $ ret13 = $c->upload($status,$pic_path,$lat,$long);
  51. if( isset($ret13['error_code']) && $ret13['error_code'] > 0 ) {
  52. echo "

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

    ";
  53. } else {
  54. echo "

    Successfully posted pictures on Weibo

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

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

    ";
  63. } else {
  64. echo "

    Follow Success

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

    ";
  72. } else {
  73. echo "

    Add tag successfully< /p>";

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

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

    ";
  82. } else {
  83. echo "

    Collection successful

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

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

    ";
  106. } else {
  107. echo "

    Comment successful

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


    Statement of this Website
    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

    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

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

    JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

    How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

    Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

    What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

    The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

    Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

    The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

    How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

    How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

    How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

    Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

    How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

    How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

    See all articles