About Weibo open Platform Oauth2.0 access website application

Source: Internet
Author: User
Tags oauth

About what is Weibo open platform and Weibo open platform can do, we do not do search engine Porter

Here is a direct link to the introduction of Weibo: Open platform

This article is just a primer, talk about the basic use of micro-BO open platform, suitable for people who have not contacted the open platform for beginners to learn, the veteran has skipped ~

Example (SINA) Weibo open platform: http://open.weibo.com/(This is the official website)

Let's take a look at Weibo open-level website access:

What is website access?

For example, we often see the major sites can directly use QQ, Weibo, and other accounts directly login, a variety of articles, games, pages of one-click Sharing, synchronization to QQ space, Weibo and other social tools such as real-time dynamic, these are open Platform website access function.

All right, don't say a word, go straight to the subject.

1, first you have to register a Sina Weibo account, and then log on to the open platform

http://open.weibo.com/

Then in the central administration, my site, add a new site to fill out some basic information about their own site, and then copy the following <meta> tag content to their home page to complete the certification.

Then record your own Wb_akey and Wb_skey (this is very important), related to security, I can not here.

On my website you can see the Web application we just filled out

2, then we can download the relevant SDK Development kit on the official website, including Java, PHP, Flash, IOS, WP7, Android and Python languages.

Download Link: Http://open.weibo.com/wiki/SDK

I personally use PHP, say this, because the SDK placed on Google, may be a bit slow to visit.

Http://code.google.com/p/libweibo/downloads/list

Here to downloadRed BoxContains a new version of the interface and the OAuth2.0 in any of the one by one compressed packages. This is the contents of the compressed package:

The following documents were introduced:

Callback.php Callback, simply said is authentication, get access_token

config.php parameter configuration file with parameters for app key,app Secret, and callback page address

index.php Home

saetv2.ex.class.php Sina Weibo operation class and authentication class, is the SDK, there are many comments can be used as API to use

Weibolist.php The functions we want to implement are all in this php page

3, the specific code implementation

First modify the configuration information inside the config.php, fill in the Wb_akey and Wb_skey we just recorded, here is to pay special attention to is Wb_callback_url Callback page address filling, HTTP can not be omitted, need to fill in the full URL

<? PHP Header (' content-type:text/html; Charset=utf-8 '); Define ("Wb_akey", ' xxxxxxxxxx ' ); Define ("Wb_skey", ' xxxxxxxxxxxxxxxxxxxxxxxxx ' ); Define ("Wb_callback_url", ' http://xxxxxxxxxxxx/callback.php ');

Then cameto index.php (here to vomit trough Sina write this demo of the staff, now PHP version does not support <?=?> this type of input format)

As an example:

<a href= "<?=$code _url?>" >

The corresponding changes to the original code, change to the echo output is good.

In the microblogging open platform before the revision, remember the inside of the demo there is a $_server[' Script_uri ' This is also not available, to correspond to the changes.

$code _url?> "></a >

Then you can upload files to their public network server , originally can be tested in the local, open platform after the revision, in order to control the environment, strict requirements.

Open our homepage index.php, click to log in with Weibo account, login success will appear the following text.

Authorization complete, access to your Weibo list page

Click on the weibolist.php page and we'll be able to see the corresponding microblogging information that corresponds to the Weibo account.

Analyze the code under weibolist.php:

1<?PHP2 Session_Start();3 4 include_once(' config.php ' );5 include_once(' saetv2.ex.class.php ' );6 7 $c=NewSaeTClientV2 (Wb_akey, Wb_skey,$_session[' token '] [' Access_token '] );8 $ms=$c->home_timeline ();// Done9 $uid _get=$c-Get_uid ();Ten $uid=$uid _get[' UID ']; One $user _message=$c-&GT;SHOW_USER_BY_ID ($uid);//get basic information such as users by ID A  -?>

In fact, the introduction of configuration files, class libraries, instantiate objects, pass parameters, call methods, return values.

Like what:

$c = new SaeTClientV2 (Wb_akey, Wb_skey, $_session[' token ' [' access_token ']);

$ms = $c->home_timeline ();

Open the class library file to find the Home_timeline method, get the current login user and their users concerned about the latest microblogging messages, API has been written very clearly, we have time to go to read the source code.

1 /**2 * Get the latest Weibo messages for the current logged-in user and the user they are interested in. 3      *4 * Get the latest Weibo messages for the current logged-in user and the user they are interested in. The same content that you see in my home page after you sign in to http://weibo.com. With Friends_timeline ()5 * <br/> corresponds to api:{@link http://open.weibo.com/wiki/2/statuses/home_timeline Statuses/home_timeline}6      * 7 * @access Public8 * @param int $page Specifies the page number that returns the result. Depending on the number of users who are currently logged in and the number of tweets posted by those who are concerned, the paging feature can view up to a different total number of records, usually up to 1000 or so. The default value is 1. Optional. 9 * @param int $count The number of records returned each time. The default value is 50, and the maximum value is 200. Optional. Ten * @param int $since _id If this parameter is specified, only microblogging messages with an ID greater than since_id (that is, Weibo messages that are later than SINCE_ID published) are returned. Optional.  One * @param int $max _id If this parameter is specified, a microblog message with an ID less than or equal to max_id is returned. Optional.  A * @param int $base _app whether to get only the data currently applied. 0 is no (all data), 1 is yes (current app only), default is 0.  - * @param int $feature filter type id,0: All, 1: Original, 2: Picture, 3: Video, 4: music, default is 0.  - * @return Array the      */ -     functionHome_timeline ($page= 1,$count= 50,$since _id= 0,$max _id= 0,$base _app= 0,$feature= 0 ) -     { -         $params=Array(); +         if($since _id) { -             $this->id_format ($since _id); +             $params[' since_id '] =$since _id; A         } at         if($max _id) { -             $this->id_format ($max _id); -             $params[' max_id '] =$max _id; -         } -         $params[' count '] =intval($count); -         $params[' page '] =intval($page); in         $params[' base_app '] =intval($base _app); -         $params[' feature '] =intval($feature); to  +         return $this->oauth->get (' Statuses/home_timeline ',$params); -}

Very simple, huh? Find some ways to try it.

Write a list of your own micro-blog to try

<? Phpsession_start(); include_once (' config.php ' ); include_once (' saetv2.ex.class.php ' ); $c = new SaeTClientV2 (Wb_akey, Wb_skey, $_session[' token ' [' Access_token ']);    
$ms  = $c->home_timeline ();//Done$uid_get = $c,get_uid (); $uid = $uid _get[' uid '];
$user _message = $c->show_user_by_id ($uid),//Get basic information such as User ID ($_post[' content ']) { $c->update ($_post[ ' content ');} else{
}?><form action= "" method= "post" ><input type= "text" name= "content"/><input type= "Submit" value= " Post Weibo "/></form>


Haha, isn't it very simple?


Try to get the attention Person ID again.
1 /**2 * Get the user's two-way attention UID List3      *4 * corresponds to api:{@link http://open.weibo.com/wiki/2/friendships/friends/bilateral/ids friendships/friends/bilateral/ IDS}5      *6 * @param int $uid need to get the user UID for the bi-directional watchlist. 7 * @param int $count The number of records returned by a single page, which defaults to 50. 8 * @param int $page Returns the page number of the result, which defaults to 1. 9 * @param int $sort sort type, 0: Most recently sorted by concern time, default is 0. Ten * @return Array One      **/ A     functionBilateral_ids ($uid,$page= 1,$count= 50,$sort= 0) -     { -         $params=Array(); the         $params[' uid '] =$uid; -         $params[' count '] =$count; -         $params[' page '] =$page; -         $params[' sort '] =$sort; +         return $this->oauth->get (' Friendships/friends/bilateral/ids ',$params  ); -}
1<?PHP2 Session_Start();3 4 include_once(' config.php ' );5 include_once(' saetv2.ex.class.php ' );6 7 $c=NewSaeTClientV2 (Wb_akey, Wb_skey,$_session[' token '] [' Access_token '] );8 $ms=$c->home_timeline ();// Done9 $uid _get=$c-Get_uid ();Ten $uid=$uid _get[' UID ']; One $user _message=$c-&GT;SHOW_USER_BY_ID ($uid);//get basic information such as users by ID A  - //Get user's bi-directional attention UID list - $info=$c->bilateral_ids ($uid); the Print_r($info); -?>

Open to get the following data:

Array ([IDs] = Array ([0] = 2365402665 [1] = 2874824370 [2] = = 2458103930 [3] = 2631415422 [4] = 1726492234 [5] = 3307625345 [6]            = 1748961617 [7] = 1898400044 [8] = 5074409657 [9] = 1459729954 [+] = 3544004403 [[]] = 2218615153 [+] = 1710952872 [+] = 3296525792 [] = 2023869922 [5142045518] [[]] = 1136908732 [[+] + [] [            [+] = 2113440863 [] = 2882182570 [] = 2750918083 [5047720995] [[+] = 3237485452 [] = 2301448374 [+] = 2241922934 [+] = 319 4061564 [29]= 1516453591 [[+] = 3046227467 [+] = 2990824405 [+] = 2901804343 [[+] = 2062251914 [] = 1846033411 [+] = 3024328843 [+] = 3989444  339 [PNS] = 3937835581 [+] = 2951303393 [+] = 38376110 [+] =            2403647687 [+] = 2637451094 [2997619907] = 2257435150 [+]            [[[]] = 2272664314 [[]] = 1858542007 [3017416653] + 3566646574 [[] = 2017817897 [] = 3270778184] [Total_number] + 198)

Then we can be based on the UID to obtain more information, such as user name, basic information and so on.

There's a little bit of content, and I'm not going to show you.

Interested friends can see more saetv2.ex.class.php file

API:HTTP://OPEN.WEIBO.COM/WIKI/%E5%BE%AE%E5%8D%9AAPI provided by the official website

Well, it's over, after all, just as an introductory introduction

Have time to write a brief introduction to the application of Weibo open platform station ~see you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.