Friendships/exists/en
Contents |
friendships/exists
Check whether user A follows user B. Returns true if it is true, otherwise returns false.
URL
http://api.t.sina.com.cn/friendships/exists.(json%7Cxml)
Supported Formats
XML/JSON
HTTP Request Method
GET
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) |
user_a | true | int64 | User A’s ID |
user_b | true | int64 | User B’s ID |
Notes
None
Example Request
- XML
- curl -u "username:password" "http://api.t.sina.com.cn/friendships/exists.xml?source=appkey&user_a=11051&user_b=11052"
- JSON
- curl -u "username:password" "http://api.t.sina.com.cn/friendships/exists.json?source=appkey&user_a=11051&user_b=11052"
Response
XML Example
<friends>true</friends>
JSON Example
{"friends":true}
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 ExistsFriendship { /** * 是否关注某用户 * @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 { //args[2]:自己的id;args[3]:关注对象的id boolean bool = getWeibo(true,args).existsFriendship(args[2],args[3]);//args[2]:关注用户的id System.out.println(bool); } 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/exists //是否关注某用户 $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); //自己的id $user_a = 'u_id'; //关注对象的id $user_b= "u_id"; $msg = $c->oauth->get('http://api.t.sina.com.cn/friendships/exists.json?user_a='.$user_a.'&user_b='.$user_b); 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['friends'])){ if ($msg['friends'] === true){ echo "true"; } else { echo "false"; } }
文档更新时间: 20 January 2011