Friendships/show

跳转到: 导航, 搜索
(使用说明)
(使用示例)
第82行: 第82行:
  
 
curl -u user:password http://api.t.sina.com.cn/friendships/show.xml?target_id=456
 
curl -u user:password http://api.t.sina.com.cn/friendships/show.xml?target_id=456
 +
====PHP示例====
 +
<pre>
 +
//Friendships/show
 +
$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->is_followed($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['target'])){
 +
if (isset($msg['target']['followed_by'])){
 +
if ($msg['target']['followed_by'] === true){
 +
echo "Target is followed: true";
 +
} else {
 +
echo "Target is followed: false";
 +
}
 +
}
 +
}
 +
</pre>

2010年8月4日 (三) 14:05的版本

目录

friendships/show

返回两个用户关系的详细情况

URL

http://api.t.sina.com.cn/friendships/show.format

格式

xml, json

HTTP请求方式

GET

是否需要身份验证

true

请求数限制

true

请求参数

以下参数可不填写,如不填,则取当前用户

  • source_id. 源用户UID
o 示例: http://api.t.sina.com.cn/friendships/show.xml?source_id=10502
  • source_screen_name. 源微博昵称
o 示例: http://api.t.sina.com.cn/friendships/show.xml?source_screen_name=bob

下面参数必须选填一个:

  • target_id. 要判断的目的用户UID
o 示例: http://api.t.sina.com.cn/friendships/show.xml?target_id=10503
  • target_screen_name. 要判断的目的微博昵称
o 示例: http://api.t.sina.com.cn/friendships/show.xml?target_screen_name=timyang

使用说明

  • 如果用户已登录,此接口将自动使用当前用户ID作为source_id。但是可强制指定source_id来查询关系
  • 如果源用户或目的用户不存在,将返回http的400错误
  • <blocking>表示source_id用户是否对target_id加黑名单,只对source_id是当前用户有效,即只能看到自己的阻止设置(blocking协议暂不支持返回)

返回结果

XML示例:

<?xml version="1.0" encoding="UTF-8"?>
<relationship>
<source>
<id>123</id>
<screen_name>bob</screen_name>
<following>true</following>
<followed_by>false</followed_by>
<notifications_enabled>false</notifications_enabled>
</source>
<target>
<id>456</id>
<screen_name>jack</screen_name>
<following>false</following>
<followed_by>true</followed_by>
<notifications_enabled></notifications_enabled>
</target>
</relationship>

JSON示例:

 {
    "source":{
        "id":245110499
        ,"screen_name":"245110499"
        ,"following":false
        ,"followed_by":false
        ,"notifications_enabled":false
   }
   ,"target":{
        "id":10503      
        ,"screen_name":"10503"
        ,"following":false
        ,"followed_by":false
        ,"notifications_enabled":false
  }
 }

使用示例

  • xml:

curl -u user:password http://api.t.sina.com.cn/friendships/show.xml?target_id=456

  • json:

curl -u user:password http://api.t.sina.com.cn/friendships/show.xml?target_id=456

PHP示例

//Friendships/show
$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->is_followed($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['target'])){
	if (isset($msg['target']['followed_by'])){
		if ($msg['target']['followed_by'] === true){
			echo "Target is followed: true";
		} else {
			echo "Target is followed: false";
		}
	}
}