Friendships/destroy

跳转到: 导航, 搜索
(创建新页面为 '== friendships/destroy == Allows the authenticating users to unfollow the user specified in the ID parameter. Returns the unfollowed user in the requested format when successfu…')
 
 
(未显示8个用户的26个中间版本)
第1行: 第1行:
== friendships/destroy ==
+
{{api_desc2|
Allows the authenticating users to unfollow the user specified in the ID parameterReturns the unfollowed user in the requested format when successfulReturns a string describing the failure condition when unsuccessful.
+
uri=friendships/destroy|
 +
desc=取消对某用户的关注。|
 +
format=XML/JSON|
 +
httpMethod=POST/DELETE|
 +
needAuth=true|
 +
rateLimit=true|
 +
params={{api_args|:id|false|int64/string|要取消关注的用户ID(int64)或者微博昵称(string),该参数是一个REST风格的参数。用法见注意事项}}
 +
{{api_args|user_id|false|int64|要取消关注的用户ID,为了避免用户的ID与微博昵称相同而产生混淆的情况,推荐使用该参数。}}
 +
{{api_args|screen_name|false|string|要取消关注的用户微博昵称,为了避免用户的ID与微博昵称相同而产生混淆的情况,推荐使用该参数。}}
 +
{{api_args_colspan|1=<font style="color:#ee3333">:id、user_id、screen_name这三个参数必填其一。</font>}}|
 +
getParam=|
 +
postParam=-d "user_id=uid"|
 +
result=
 +
===XML示例===
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<user>
 +
  <id>1474388131</id>
 +
  <screen_name>.......</screen_name>
 +
  <name>.......</name>
 +
  <province>11</province>
 +
  <city>8</city>
 +
  <location>北京 海淀区</location>
 +
  <description>.......</description>
 +
  <url>http://1</url>
 +
  <profile_image_url>http://tp4.sinaimg.cn/1474388131/50/1287032732/1</profile_image_url>
 +
  <domain>.......</domain>
 +
  <gender>m</gender>
 +
  <followers_count>40</followers_count>
 +
  <friends_count>97</friends_count>
 +
  <statuses_count>88</statuses_count>
 +
  <favourites_count>0</favourites_count>
 +
  <created_at>Tue Jul 13 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>
 +
  <status>
 +
    <created_at>Mon Dec 06 10:24:28 +0800 2010</created_at>
 +
    <id>4116374877</id>
 +
    <text>生死簿上记载,我的寿命还有17437天(约48年) http://sinaurl.cn/hbyVR6</text>
 +
    <source>
 +
      <a href="http://wanyi.sinaapp.com">玩意网</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://ww1.sinaimg.cn/thumbnail/57e160a3jw6dc2ondgoytg.gif</thumbnail_pic>
 +
    <bmiddle_pic>http://ww1.sinaimg.cn/bmiddle/57e160a3jw6dc2ondgoytg.gif</bmiddle_pic>
 +
    <original_pic>http://ww1.sinaimg.cn/large/57e160a3jw6dc2ondgoytg.gif</original_pic>
 +
  </status>
 +
</user>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
{
 +
    "name" : "........",
 +
    "domain" : ".........",
 +
    "geo_enabled" : true,
 +
    "followers_count" : 40,
 +
    "statuses_count" : 88,
 +
    "favourites_count" : 0,
 +
    "city" : "8",
 +
    "description" : ".......",
 +
    "verified" : false,
 +
    "status" :
 +
    {
 +
        "created_at" : "Mon Dec 06 10:24:28 +0800 2010",
 +
        "text" : "生死簿上记载,我的寿命还有17437天(约48年) http://sinaurl.cn/hbyVR6",
 +
        "bmiddle_pic" : "http://ww1.sinaimg.cn/bmiddle/57e160a3jw6dc2ondgoytg.gif",
 +
        "original_pic" : "http://ww1.sinaimg.cn/large/57e160a3jw6dc2ondgoytg.gif",
 +
        "truncated" : false,
 +
        "in_reply_to_status_id" : "",
 +
        "in_reply_to_screen_name" : "",
 +
        "geo" : null,
 +
        "favorited" : false,
 +
        "thumbnail_pic" : "http://ww1.sinaimg.cn/thumbnail/57e160a3jw6dc2ondgoytg.gif",
 +
        "in_reply_to_user_id" : "",
 +
        "id" : 4116374877,
 +
        "source" : "<a href=\"http://wanyi.sinaapp.com\" rel=\"nofollow\">玩意网</a>"
 +
    },
 +
    "id" : 1474388131,
 +
    "gender" : "m",
 +
    "friends_count" : 97,
 +
    "screen_name" : ".......",
 +
    "allow_all_act_msg" : false,
 +
    "following" : false,
 +
    "url" : "http://1",
 +
    "profile_image_url" : "http://tp4.sinaimg.cn/1474388131/50/1287032732/1",
 +
    "created_at" : "Tue Jul 13 00:00:00 +0800 2010",
 +
    "province" : "11",
 +
    "location" : "北京 海淀区"
 +
}
 +
</pre>
 +
{{param_user}}
 +
{{param_status}}|
 +
useAge=
 +
* :id为REST风格的参数,使用该参数的URL为:<br/> http://api.t.sina.com.cn/friendships/destroy/:id.format <br/> 使用示例如下:<br/> http://api.t.sina.com.cn/friendships/destroy/123456.xml?source=appkey<br/>http://api.t.sina.com.cn/friendships/destroy/123456.json?source=appkey
 +
* 关注不存在的ID返回400
 +
*<font style="color:red">此接口仅针对微博类客户端开放,非微博类客户端应用不开放此接口权限。</font>|
 +
* 如果已经关注了此人,则返回http 403的状态。|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
<pre>
 +
package weibo4j.examples;
  
=== URL: ===
+
import weibo4j.Weibo;
http://api.t.sina.com.cn/friendships/destroy/id.format
+
import weibo4j.WeiboException;
+
===Formats:===
+
xml, json
+
+
=== HTTP Method(s): ===
+
POST, DELETE
+
+
===Requires Authentication (about authentication):===
+
true
+
+
===API rate limited (about rate limiting):===
+
false
+
+
===Parameters:===
+
One of the following is required:
+
* id.  Required. The ID or screen name of the user to unfollow. 
+
Example: http://api.t.sina.com.cn/friendships/destroy/12345.json or http://api.t.sina.com.cn/friendships/destroy/bob.xml
+
* user_id. Required. Specfies the ID of the user to unfollow. Helpful for disambiguating when a valid user ID is also a valid screen name.
+
o Example: http://api.t.sina.com.cn/friendships/destroy.xml?user_id=1401881
+
* screen_name. Required. Specfies the screen name of the user to unfollow. Helpful for disambiguating when a valid screen name is also a user ID.
+
o Example: http://api.t.sina.com.cn/friendships/destroy.xml?screen_name=101010
+
  
===Response (about return values): ===
+
public class DestroyFriendship {
XML example (truncated):
+
<?xml version="1.0" encoding="UTF-8"?>
+
<user>
+
<id>1401881</id>
+
<name>Doug Williams</name>
+
<screen_name>dougw</screen_name>
+
<location>San Francisco, CA</location>
+
<description>Twitter API Support. Internet, greed, users, dougw and opportunities are my passions.</description>
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/59648642/avatar_normal.png</profile_image_url>
+
<url>http://www.igudo.com</url>
+
<protected>false</protected>
+
<followers_count>1031</followers_count>
+
<profile_background_color>9ae4e8</profile_background_color>
+
<profile_text_color>000000</profile_text_color>
+
<profile_link_color>0000ff</profile_link_color>
+
<profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>
+
<profile_sidebar_border_color>87bc44</profile_sidebar_border_color>
+
<friends_count>293</friends_count>
+
<created_at>Sun Mar 18 06:42:26 +0000 2007</created_at>
+
<favourites_count>0</favourites_count>
+
<utc_offset>-18000</utc_offset>
+
<time_zone>Eastern Time (US & Canada)</time_zone>
+
<profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/2752608/twitter_bg_grass.jpg</profile_background_image_url>
+
<profile_background_tile>false</profile_background_tile>
+
<statuses_count>3390</statuses_count>
+
<notifications>false</notifications>
+
<following>false</following>
+
<verified>true</verified>
+
<status>
+
<created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
+
<id>1472669360</id>
+
<text>At least I can get your humor through tweets. RT @abdur: I don't mean this in a bad way, but genetically speaking your a cul-de-sac.</text>
+
<source><a href="http://www.tweetdeck.com/">TweetDeck</a></source>
+
<truncated>false</truncated>
+
<in_reply_to_status_id></in_reply_to_status_id>
+
<in_reply_to_user_id></in_reply_to_user_id>
+
<favorited>false</favorited>
+
<in_reply_to_screen_name></in_reply_to_screen_name>
+
</status>
+
</user>
+
  
===Usage examples: ===
+
/**
cURL (about cURL):
+
* 取消关注
 
+
* @param args
curl -u user:password -d "" http://api.t.sina.com.cn/friendships/destroy/dougw.xml
+
*/
 +
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).destroyFriendship(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;
 +
}
 +
}</pre>
 +
===PHP示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>
 +
代码示例如下:
 +
<pre>
 +
//friendships/destroy
 +
//取消关注
 +
$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->unfollow($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('Unfollow Friend:'.$msg['screen_name']);
 +
}
 +
</pre>
 +
}}

2015年6月24日 (三) 17:36的最后版本

目录

friendships/destroy

取消对某用户的关注。

URL

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

支持格式

XML/JSON

HTTP请求方式

POST/DELETE

是否需要登录

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

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
:id false int64/string 要取消关注的用户ID(int64)或者微博昵称(string),该参数是一个REST风格的参数。用法见注意事项
user_id false int64 要取消关注的用户ID,为了避免用户的ID与微博昵称相同而产生混淆的情况,推荐使用该参数。
screen_name false string 要取消关注的用户微博昵称,为了避免用户的ID与微博昵称相同而产生混淆的情况,推荐使用该参数。
:id、user_id、screen_name这三个参数必填其一。

注意事项

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id>1474388131</id>
  <screen_name>.......</screen_name>
  <name>.......</name>
  <province>11</province>
  <city>8</city>
  <location>北京 海淀区</location>
  <description>.......</description>
  <url>http://1</url>
  <profile_image_url>http://tp4.sinaimg.cn/1474388131/50/1287032732/1</profile_image_url>
  <domain>.......</domain>
  <gender>m</gender>
  <followers_count>40</followers_count>
  <friends_count>97</friends_count>
  <statuses_count>88</statuses_count>
  <favourites_count>0</favourites_count>
  <created_at>Tue Jul 13 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>
  <status>
    <created_at>Mon Dec 06 10:24:28 +0800 2010</created_at>
    <id>4116374877</id>
    <text>生死簿上记载,我的寿命还有17437天(约48年)  http://sinaurl.cn/hbyVR6</text>
    <source>
      <a href="http://wanyi.sinaapp.com">玩意网</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://ww1.sinaimg.cn/thumbnail/57e160a3jw6dc2ondgoytg.gif</thumbnail_pic>
    <bmiddle_pic>http://ww1.sinaimg.cn/bmiddle/57e160a3jw6dc2ondgoytg.gif</bmiddle_pic>
    <original_pic>http://ww1.sinaimg.cn/large/57e160a3jw6dc2ondgoytg.gif</original_pic>
  </status>
</user>

JSON示例

{
    "name" : "........",
    "domain" : ".........",
    "geo_enabled" : true,
    "followers_count" : 40,
    "statuses_count" : 88,
    "favourites_count" : 0,
    "city" : "8",
    "description" : ".......",
    "verified" : false,
    "status" : 
    {
        "created_at" : "Mon Dec 06 10:24:28 +0800 2010",
        "text" : "生死簿上记载,我的寿命还有17437天(约48年)  http://sinaurl.cn/hbyVR6",
        "bmiddle_pic" : "http://ww1.sinaimg.cn/bmiddle/57e160a3jw6dc2ondgoytg.gif",
        "original_pic" : "http://ww1.sinaimg.cn/large/57e160a3jw6dc2ondgoytg.gif",
        "truncated" : false,
        "in_reply_to_status_id" : "",
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "favorited" : false,
        "thumbnail_pic" : "http://ww1.sinaimg.cn/thumbnail/57e160a3jw6dc2ondgoytg.gif",
        "in_reply_to_user_id" : "",
        "id" : 4116374877,
        "source" : "<a href=\"http://wanyi.sinaapp.com\" rel=\"nofollow\">玩意网</a>"
    },
    "id" : 1474388131,
    "gender" : "m",
    "friends_count" : 97,
    "screen_name" : ".......",
    "allow_all_act_msg" : false,
    "following" : false,
    "url" : "http://1",
    "profile_image_url" : "http://tp4.sinaimg.cn/1474388131/50/1287032732/1",
    "created_at" : "Tue Jul 13 00:00:00 +0800 2010",
    "province" : "11",
    "location" : "北京 海淀区"
}

字段说明 - user

  • id: 用户UID
  • screen_name: 微博昵称
  • name: 友好显示名称,同微博昵称
  • province: 省份编码(参考省份编码表)
  • city: 城市编码(参考城市编码表)
  • location:地址
  • description: 个人描述
  • url: 用户博客地址
  • profile_image_url: 自定义图像
  • domain: 用户个性化URL
  • gender: 性别,m--男,f--女,n--未知
  • followers_count: 粉丝数
  • friends_count: 关注数
  • statuses_count: 微博数
  • favourites_count: 收藏数
  • created_at: 创建时间
  • following: 是否已关注(此特性暂不支持)
  • verified: 加V标示,是否微博认证用户

字段说明 - status

  • created_at: 创建时间
  • id: 微博ID
  • text: 微博信息内容
  • source: 微博来源
  • favorited: 是否已收藏
  • truncated: 是否被截断
  • in_reply_to_status_id: 回复ID
  • in_reply_to_user_id: 回复人UID
  • in_reply_to_screen_name: 回复人昵称
  • thumbnail_pic: 缩略图
  • bmiddle_pic: 中型图片
  • original_pic:原始图片
  • user: 作者信息
  • retweeted_status: 转发的博文,内容为status,如果不是转发,则没有此字段

其他

Java示例

请从 微博SDK开发包下载 下载Java SDK
代码示例如下:

package weibo4j.examples;

import weibo4j.Weibo;
import weibo4j.WeiboException;

public class DestroyFriendship {

	/**
	 * 取消关注
	 * @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).destroyFriendship(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示例

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

//friendships/destroy
//取消关注
$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->unfollow($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('Unfollow Friend:'.$msg['screen_name']);
}
文档更新时间: 2015-06-24