Friendships/create/en
目录 |
friendships/create
Follows a user. Returns the befriended user’s profile when successful. Currently can only follow up to 2000 users.
URL
http://api.t.sina.com.cn/friendships/create.(json%7Cxml)
Supported Formats
XML/JSON
HTTP Request Method
POST
Requires Authentication
true
See the Authorization Mechanism Statement for authorization details
Requests Count Limitation
true
See the Interface Access Rights Statement for the Request Count Limitaiton details.
Request Parameters
Requires | Type and Range | Description | |
---|---|---|---|
source | true | string | AppKey for the application to identify it. ( This parameter is not needed when using OAuth) |
:id | false | int64/string | The ID(int64) or screen-name(string) of the user to be friended. It is a RESTful parameter. On usage please see Notes. |
user_id | false | int64 | Specfies the ID of the user to befriend. Helpful for disambiguating when a valid user ID is also a valid screen name. |
screen_name | false | string | Specfies the screen name of the user to befriend. Helpful for disambiguating when a valid screen name is also a user ID. |
Id, user_id, screen_name: one of theses three parameters is required. |
Notes
- :id is a RESTful parameter. URL of using this parameter:
http://api.t.sina.com.cn/friendships/create/:id.format
Usage examples:
http://api.t.sina.com.cn/friendships/create/1658122963.xml?source=appkey
http://api.t.sina.com.cn/friendships/create/zhangwei217245.json?source=appkey - Returns 400 error when follows a not exist ID.
- Returns HTTP 403 status when the user has already been friended.
Example Request
- XML
- curl -u "username:password" -d "user_id=1658122963" "http://api.t.sina.com.cn/friendships/create.xml?source=appkey"
- JSON
- curl -u "username:password" -d "user_id=1658122963" "http://api.t.sina.com.cn/friendships/create.json?source=appkey"
Response
XML Example
<?xml version="1.0" encoding="UTF-8"?> <user> <id>1658122963</id> <screen_name>zhangwei217245</screen_name> <name>zhangwei217245</name> <province>11</province> <city>5</city> <location>北京 朝阳区</location> <description>ABCDE</description> <url/> <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url> <domain>zhangwei217245</domain> <gender>m</gender> <followers_count>25</followers_count> <friends_count>46</friends_count> <statuses_count>119</statuses_count> <favourites_count>3</favourites_count> <created_at>Tue Nov 03 00:00:00 +0800 2009</created_at> <following>false</following> <verified>false</verified> <allow_all_act_msg>false</allow_all_act_msg> <geo_enabled>true</geo_enabled> <status> <created_at>Mon Dec 06 13:47:10 +0800 2010</created_at> <id>4120818179</id> <text>一个存储系统~~~ 姑且认为是标题党</text> <source> <a href="http://t.sina.com.cn">新浪微博</a> </source> <favorited>false</favorited> <truncated>false</truncated> <geo/> <in_reply_to_status_id/> <in_reply_to_user_id/> <in_reply_to_screen_name/> <retweeted_status> <created_at>Mon Dec 06 11:09:56 +0800 2010</created_at> <id>4117314145</id> <text>一个存储系统,从高到底设计非常人性,太有爱了!(Via:http://sinaurl.cn/hb5abi)</text> <source> <a href="http://t.sina.com.cn">新浪微博</a> </source> <favorited>false</favorited> <truncated>false</truncated> <geo/> <in_reply_to_status_id/> <in_reply_to_user_id/> <in_reply_to_screen_name/> <thumbnail_pic>http://ww2.sinaimg.cn/thumbnail/69b7fcafgw6dc2pwus9ekg.gif</thumbnail_pic> <bmiddle_pic>http://ww2.sinaimg.cn/bmiddle/69b7fcafgw6dc2pwus9ekg.gif</bmiddle_pic> <original_pic>http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif</original_pic> <user> <id>1773665455</id> <screen_name>MADBRIEF</screen_name> <name>MADBRIEF</name> <province>33</province> <city>3</city> <location>浙江 温州</location> <description>疯狂简报 | MADBRIEF.Com 关于创意与生意</description> <url>http://www.madbrief.com/</url> <profile_image_url>http://tp4.sinaimg.cn/1773665455/50/1290503872/1</profile_image_url> <domain>madbrief</domain> <gender>m</gender> <followers_count>929</followers_count> <friends_count>565</friends_count> <statuses_count>1581</statuses_count> <favourites_count>0</favourites_count> <created_at>Mon Jul 12 00:00:00 +0800 2010</created_at> <following>false</following> <verified>false</verified> <allow_all_act_msg>false</allow_all_act_msg> <geo_enabled>true</geo_enabled> </user> <annotations/> </retweeted_status> <annotations/> </status> </user>
JSON Example
{ "name" : "zhangwei217245", "domain" : "zhangwei217245", "geo_enabled" : true, "followers_count" : 25, "statuses_count" : 119, "favourites_count" : 3, "city" : "5", "description" : "ABCDE", "verified" : false, "status" : { "created_at" : "Mon Dec 06 13:47:10 +0800 2010", "text" : "一个存储系统~~~ 姑且认为是标题党", "truncated" : false, "retweeted_status" : { "created_at" : "Mon Dec 06 11:09:56 +0800 2010", "text" : "一个存储系统,从高到底设计非常人性,太有爱了!(Via:http://sinaurl.cn/hb5abi)", "bmiddle_pic" : "http://ww2.sinaimg.cn/bmiddle/69b7fcafgw6dc2pwus9ekg.gif", "original_pic" : "http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif", "truncated" : false, "in_reply_to_status_id" : "", "annotations" : [ ], "in_reply_to_screen_name" : "", "geo" : null, "user" : { "name" : "MADBRIEF", "domain" : "madbrief", "geo_enabled" : true, "followers_count" : 929, "statuses_count" : 1581, "favourites_count" : 0, "city" : "3", "description" : "疯狂简报 | MADBRIEF.Com 关于创意与生意", "verified" : false, "id" : 1773665455, "gender" : "m", "friends_count" : 565, "screen_name" : "MADBRIEF", "allow_all_act_msg" : false, "following" : false, "url" : "http://www.madbrief.com/", "profile_image_url" : "http://tp4.sinaimg.cn/1773665455/50/1290503872/1", "created_at" : "Mon Jul 12 00:00:00 +0800 2010", "province" : "33", "location" : "浙江 温州" }, "favorited" : false, "thumbnail_pic" : "http://ww2.sinaimg.cn/thumbnail/69b7fcafgw6dc2pwus9ekg.gif", "in_reply_to_user_id" : "", "id" : 4117314145, "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>" }, "in_reply_to_status_id" : "", "annotations" : [ ], "in_reply_to_screen_name" : "", "geo" : null, "favorited" : false, "in_reply_to_user_id" : "", "id" : 4120818179, "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>" }, "id" : 1658122963, "gender" : "m", "friends_count" : 46, "screen_name" : "zhangwei217245", "allow_all_act_msg" : false, "following" : false, "url" : "", "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213", "created_at" : "Tue Nov 03 00:00:00 +0800 2009", "province" : "11", "location" : "北京 朝阳区" }
Field Description - user
- id: User ID
- screen_name: User’s nickname displayed on the home page
- name: Friendly displayed name, the same as screen_name
- province: Province code ( see Province and city code table)
- city: City code ( see Province and city code table)
- location:Address
- description: Personal description
- url: Url of the user’s blog
- profile_image_url: Profile image
- domain: The user’s personalized weibo url
- gender: Gender, m—male, f- - female, n-- unknown
- followers_count: Followers count
- friends_count: Following count
- statuses_count: Weibo count
- favourites_count: Favorites count
- created_at: Created time
- following: Whether the current user is following the user that posts the weibo (Not supported yet)
- verified: Whether the user is verified by his real identity, marked with “V”
Field Description - weibo
- created_at: Create time
- id: Weibo ID
- text: Weibo content
- source: Weibo source
- favorited: Whether it is favroited
- truncated: Whether it is truncated
- in_reply_to_status_id: The reply’s ID
- in_reply_to_user_id: UID of the replyer
- in_reply_to_screen_name: Nickname of replyer
- thumbnail_pic: Thumbnail picture
- bmiddle_pic: Medium picture
- original_pic:Original picture
- user: User profile
- retweeted_status: eposted weibo content, the content is the status, This filed is only available for a reposted weibo.
Others
Java Example
Please download Java SDK from . Weibo SDK Development Kit Dowload Site
Sample Code:
package weibo4j.examples; import weibo4j.Weibo; import weibo4j.WeiboException; public class CreateFriendship { /** * 关注某用户 * @param args */ public static void main(String[] args) { System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); try { User user = getWeibo(true,args).createFriendship(args[2]);//args[2]:关注用户的id System.out.println(user.toString()); } catch (WeiboException e) { e.printStackTrace(); } } private static Weibo getWeibo(boolean isOauth,String[] args) { Weibo weibo = new Weibo(); if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙 weibo.setToken(args[0], args[1]); }else {//用户登录方式 weibo.setUserId(args[0]);//用户名/ID weibo.setPassword(args[1]);//密码 } return weibo; } }
PHP Example
Please download PHP SDK with OAUTH supported from Weibo SDK Development Kit Dowload Site
.
Sample Code:
//friendships/create //关注某用户 $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); //关注用户的id $u_id = "U_ID"; $msg = $c->follow($u_id); if ($msg === false || $msg === null){ echo "Error occured"; return false; } if (isset($msg['error_code']) && isset($msg['error'])){ echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] ); return false; } if (isset($msg['screen_name'])){ echo('New Friend:'.$msg['screen_name']); }
文档更新时间: 2011-01-20