Friendships/exists
第90行: | 第90行: | ||
} | } | ||
</pre> | </pre> | ||
− | + | }} |
2012年9月24日 (一) 11:40的最后版本
目录 |
friendships/exists
查看用户A是否关注了用户B。如果用户A关注了用户B,则返回true,否则返回false。
URL
http://api.t.sina.com.cn/friendships/exists.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
GET
是否需要登录
true
关于授权机制,参见授权机制声明
请求数限制
true
关于请求数限制,参见接口访问权限说明
请求参数
必选 | 类型及范围 | 说明 | |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数) |
user_a | true | int64 | 用户A的用户ID |
user_b | true | int64 | 用户B的用户ID |
注意事项
无
返回结果
XML示例
<friends>true</friends>
JSON示例
{"friends":true}
其他
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示例如下:
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示例
请从 微博SDK开发包下载 处下载PHP SDK(支持OAuth验证之版本)
代码示例如下:
//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"; } }
文档更新时间: 2012-09-24