Friendships/show

跳转到: 导航, 搜索
(创建新页面为 '== friendships/show == Returns detailed information about the relationship between two users. === URL: === http://api.t.sina.com.cn/friendships/show.format ===Formats:=== xml…')
 
 
(未显示6个用户的21个中间版本)
第1行: 第1行:
== friendships/show ==
+
{{api_desc2|
Returns detailed information about the relationship between two users.
+
uri=friendships/show|
 
+
desc=返回两个用户关注关系的详细情况|
=== URL: ===
+
format=XML/JSON|
http://api.t.sina.com.cn/friendships/show.format
+
httpMethod=GET|
+
needAuth=true|
===Formats:===
+
rateLimit=true|
xml, json
+
params={{api_args_colspan|1=<div style="color:#FFFFFF;background-color:#bbbbbb;font-weight:bold;text-align:left;padding-left:10px">以下参数可不填,如果不填,则默认取当前登录用户</div>}}
+
{{api_args|source_id|false|int64|源用户UID}}
=== HTTP Method(s): ===
+
{{api_args|source_screen_name|false|string|源微博昵称}}
GET
+
{{api_args_colspan|1=<div style="color:#FFFFFF;background-color:#bbbbbb;font-weight:bold;text-align:left;padding-left:10px">以下参数必选其一</div>}}
+
{{api_args|target_id|false|int64|要判断的目标用户ID }}
===Requires Authentication (about authentication):===
+
{{api_args|target_screen_name|false|string|要判断的目标用户的微博昵称}}|
false (see usage notes)
+
getParam=&target_id=456|
+
postParam=|
===API rate limited (about rate limiting):===
+
result=
true
+
===XML示例===
+
<pre>
===Parameters:===
+
<?xml version="1.0" encoding="UTF-8"?>
One of the following is required if the request is unauthenticated:
+
* source_id. The user_id of the subject user.
+
o Example: http://api.t.sina.com.cn/friendships/show.xml?source_id=123
+
* source_screen_name. The screen_name of the subject user.
+
o Example: http://api.t.sina.com.cn/friendships/show.xml?source_screen_name=bob
+
One of the following is required:
+
* target_id. The user_id of the target user.
+
o Example: http://api.t.sina.com.cn/friendships/show.xml?target_id=456
+
* target_screen_name. The screen_name of the target user.
+
o Example: http://api.t.sina.com.cn/friendships/show.xml?target_screen_name=jack
+
 
+
===Usage Notes:===
+
* If this method is invoked as an authenticated request, the method will use the authenticated user as the source user implicitly. However, a source explicitly specified with parameters will override an authenticated user as the source of the relationship query.
+
* If the source is not specified for an unauthenticated request, the method will return an HTTP 403.
+
* If a source or target is specified but does not exist, the method will return an HTTP 404.
+
* The <notifications_enabled> element will only be returned for an authenticated source user within the <source> element. Notification data is not publicly available data and therefore remains restricted to authenticated users within the API. For unauthenticated source users and target users, the <notifications_enabled> element will be empty.
+
* This method returns redundant data, in that the bi-directional relationship of the source and target can be determined by looking at the <following> and <followed_by> element within either the <source> or <target> nodes. We deliver this data twice in denormalized form for convenience and increased readability.
+
 
+
 
+
===Response (about return values): ===
+
XML example:
+
<?xml version="1.0" encoding="UTF-8"?>
+
 
  <relationship>
 
  <relationship>
 
  <source>
 
  <source>
第56行: 第34行:
 
  </target>
 
  </target>
 
  </relationship>
 
  </relationship>
JSON example:
+
</pre>
{"relationship": {
+
===JSON示例===
"source": {
+
<pre>
"id": 123,
+
  {
"screen_name": "bob",
+
    "source":{
"following": true,
+
        "id":245110499
"followed_by": false,
+
        ,"screen_name":"245110499"
"notifications_enabled": false },
+
        ,"following":false
"target": {
+
        ,"followed_by":false
"id": 456,
+
        ,"notifications_enabled":false
"screen_name": "jack",
+
    }
"following": false,
+
    ,"target":{
"followed_by": true,
+
        "id":10503     
"notifications_enabled": null }
+
        ,"screen_name":"10503"
 +
        ,"following":false
 +
        ,"followed_by":false
 +
        ,"notifications_enabled":false
 +
  }
 
  }
 
  }
}
+
</pre>|
 
+
useAge=
===Usage examples: ===
+
* 如果用户已登录,此接口将自动使用当前用户ID作为source_id。但是可强制指定source_id来查询关注关系。
cURL (about cURL):
+
* 如果源用户或目的用户不存在,将返回http的400错误
 +
* <blocking>表示source_id用户是否对target_id加黑名单,只对source_id是当前用户有效,即只能看到自己的阻止设置(blocking协议暂不支持返回)|
 +
otherInfo=
 +
===PHP示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>
 +
代码示例如下:
 +
<pre>
 +
//Friendships/show
 +
$c = new WeiboClient( WB_AKEY ,
 +
                      WB_SKEY ,
 +
                      $_SESSION['last_key']['oauth_token'] ,
 +
                      $_SESSION['last_key']['oauth_token_secret']  );
  
curl -u user:password http://api.t.sina.com.cn/friendships/show.xml?target_id=456
+
//关注对象的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>
 +
}}

2012年9月24日 (一) 11:40的最后版本

目录

friendships/show

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

URL

http://api.t.sina.com.cn/friendships/show.(json%7Cxml)

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

true
关于授权机制,参见授权机制声明

请求数限制

true
关于请求数限制,参见接口访问权限说明

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
以下参数可不填,如果不填,则默认取当前登录用户
source_id false int64 源用户UID
source_screen_name false string 源微博昵称
以下参数必选其一
target_id false int64 要判断的目标用户ID
target_screen_name false string 要判断的目标用户的微博昵称

注意事项

  • 如果用户已登录,此接口将自动使用当前用户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
   }
 }

其他

PHP示例

请从 微博SDK开发包下载 处下载PHP SDK(支持OAuth验证之版本)
代码示例如下:

//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";
		}
	}
}
文档更新时间: 2012-09-24