Friendships/create

跳转到: 导航, 搜索
(必选参数(至少选一个))
(返回结果)
第31行: 第31行:
  
 
XML示例:
 
XML示例:
  <?xml version="1.0" encoding="UTF-8"?>
+
<pre>
  <user>
+
<?xml version="1.0" encoding="UTF-8"?>
    <id>11075</id>
+
<user>
    <screen_name>name_11075</screen_name>
+
  <id>1266321801</id>
    <name>name_11075</name>
+
  <screen_name>姚晨</screen_name>
    <province>0</province>
+
  <name>姚晨</name>
    <city>0</city>
+
  <province>11</province>
    <location></location>
+
  <city>5</city>
    <description></description>
+
  <location>北京 朝阳区</location>
    <url></url>
+
  <description>一颗很逊的卤蛋。</description>
    <profile_image_url>http://tp4.sinaimg.cn/11075/50/0</profile_image_url>
+
  <url>http://blog.sina.com.cn/yaochen</url>
    <domain>11075</domain>
+
  <profile_image_url>http://tp2.sinaimg.cn/1266321801/50/1283203855</profile_image_url>
    <gender></gender>
+
  <domain>yaochen</domain>
    <followers_count>28</followers_count>
+
  <gender>f</gender>
    <friends_count>50</friends_count>
+
  <followers_count>2786967</followers_count>
    <statuses_count>29</statuses_count>
+
  <friends_count>561</friends_count>
    <favourites_count>0</favourites_count>
+
  <statuses_count>2148</statuses_count>
    <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at>
+
  <favourites_count>10</favourites_count>
    <following>false</following>
+
  <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at>
    <verified>true</verified>
+
  <following>false</following>
    <geo_enabled>false</geo_enabled>
+
  <verified>true</verified>
    <status>
+
  <allow_all_act_msg>false</allow_all_act_msg>
       <created_at>Thu Jan 07 17:36:07 +0800 2010</created_at>
+
  <geo_enabled>false</geo_enabled>
       <id>142309</id>
+
  <status>
       <text>要查询的微博ID</text>
+
    <created_at>Fri Sep 10 09:47:00 +0800 2010</created_at>
 +
    <id>2465393025</id>
 +
    <text>愿我永远不要失去给他人带来快乐的能力,因为失去它,自己也不可能再拥有快乐。</text>
 +
    <source>
 +
      <a href="http://news.sina.com.cn/wap/wbclient.html#3">iPhone客户端</a>
 +
    </source>
 +
    <favorited>false</favorited>
 +
    <truncated>false</truncated>
 +
    <geo/>
 +
    <in_reply_to_status_id/>
 +
    <in_reply_to_user_id/>
 +
    <in_reply_to_screen_name/>
 +
    <retweeted_status>
 +
       <created_at>Fri Sep 10 08:00:03 +0800 2010</created_at>
 +
       <id>2463041144</id>
 +
       <text>许多人知道如何享乐,却不知道自己从何时起已不再向别人提供欢乐。(BY阿瑟·赫尔普斯)早安,各位。</text>
 
       <source>
 
       <source>
         <a id="0" href="http://t.sina.com.cn">Web</a>
+
         <a href="http://t.sina.com.cn">新浪微博</a>
 
       </source>
 
       </source>
 
       <favorited>false</favorited>
 
       <favorited>false</favorited>
 
       <truncated>false</truncated>
 
       <truncated>false</truncated>
 
       <geo/>
 
       <geo/>
       <in_reply_to_status_id></in_reply_to_status_id>
+
       <in_reply_to_status_id/>
       <in_reply_to_user_id></in_reply_to_user_id>
+
      <in_reply_to_user_id/>
       <in_reply_to_screen_name></in_reply_to_screen_name>
+
       <in_reply_to_screen_name/>
     </status>
+
      <thumbnail_pic>http://ss16.sinaimg.cn/thumbnail/62914aabt8fdc6a2f6c0f&amp;690</thumbnail_pic>
   </user>
+
       <bmiddle_pic>http://ss16.sinaimg.cn/bmiddle/62914aabt8fdc6a2f6c0f&amp;690</bmiddle_pic>
 
+
      <original_pic>http://ss16.sinaimg.cn/orignal/62914aabt8fdc6a2f6c0f&amp;690</original_pic>
 +
      <user>
 +
        <id>1653689003</id>
 +
        <screen_name>新周刊</screen_name>
 +
        <name>新周刊</name>
 +
        <province>44</province>
 +
        <city>1</city>
 +
        <location>广东 广州</location>
 +
        <description>《新周刊》,中国最新锐的时事生活周刊:观点供应商,视觉开发商,资讯整合商,传媒运营商。</description>
 +
        <url>http://blog.sina.com.cn/xinzhoukan</url>
 +
        <profile_image_url>http://tp4.sinaimg.cn/1653689003/50/1283204286</profile_image_url>
 +
        <domain>neweekly</domain>
 +
        <gender>m</gender>
 +
        <followers_count>559667</followers_count>
 +
        <friends_count>203</friends_count>
 +
        <statuses_count>5748</statuses_count>
 +
        <favourites_count>10</favourites_count>
 +
        <created_at>Wed Oct 14 00:00:00 +0800 2009</created_at>
 +
        <following>false</following>
 +
        <verified>true</verified>
 +
        <allow_all_act_msg>false</allow_all_act_msg>
 +
        <geo_enabled>false</geo_enabled>
 +
      </user>
 +
     </retweeted_status>
 +
   </status>
 +
</user>
 +
</pre>
 
JSON示例:
 
JSON示例:
  

2010年9月10日 (五) 11:55的版本

目录

friendships/create

关注一个用户。成功则返回关注人的资料,目前的最多关注2000人,失败则返回一条字符串的说明。如果已经关注了此人,则返回http 403的状态.

URL

http://api.t.sina.com.cn/friendships/create/id.format

格式

xml, json

HTTP请求方式

POST

是否需要身份验证

true

请求参数

必选参数(至少选一个)

  • id: 要关注的用户UID或微博昵称
示例: http://api.t.sina.com.cn/friendships/create/12345.json or http://api.t.sina.com.cn/friendships/create/bob.xml
  • user_id: 要关注的用户UID,主要是用在区分用户UID跟微博昵称一样,产生歧义的时候。
示例: http://api.t.sina.com.cn/friendships/create.xml?user_id=1401881
  • screen_name: 要关注的微博昵称,主要是用在区分用户UID跟微博昵称一样,产生歧义的时候。
示例: http://api.t.sina.com.cn/friendships/create.xml?screen_name=101010
  • follow. 可选参数。暂不支持。

使用说明

  • 此接口有更新上限,越权将返回http 403 错误
  • 关注不存在的ID返回400

返回结果

XML示例:

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id>1266321801</id>
  <screen_name>姚晨</screen_name>
  <name>姚晨</name>
  <province>11</province>
  <city>5</city>
  <location>北京 朝阳区</location>
  <description>一颗很逊的卤蛋。</description>
  <url>http://blog.sina.com.cn/yaochen</url>
  <profile_image_url>http://tp2.sinaimg.cn/1266321801/50/1283203855</profile_image_url>
  <domain>yaochen</domain>
  <gender>f</gender>
  <followers_count>2786967</followers_count>
  <friends_count>561</friends_count>
  <statuses_count>2148</statuses_count>
  <favourites_count>10</favourites_count>
  <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at>
  <following>false</following>
  <verified>true</verified>
  <allow_all_act_msg>false</allow_all_act_msg>
  <geo_enabled>false</geo_enabled>
  <status>
    <created_at>Fri Sep 10 09:47:00 +0800 2010</created_at>
    <id>2465393025</id>
    <text>愿我永远不要失去给他人带来快乐的能力,因为失去它,自己也不可能再拥有快乐。</text>
    <source>
      <a href="http://news.sina.com.cn/wap/wbclient.html#3">iPhone客户端</a>
    </source>
    <favorited>false</favorited>
    <truncated>false</truncated>
    <geo/>
    <in_reply_to_status_id/>
    <in_reply_to_user_id/>
    <in_reply_to_screen_name/>
    <retweeted_status>
      <created_at>Fri Sep 10 08:00:03 +0800 2010</created_at>
      <id>2463041144</id>
      <text>许多人知道如何享乐,却不知道自己从何时起已不再向别人提供欢乐。(BY阿瑟·赫尔普斯)早安,各位。</text>
      <source>
        <a href="http://t.sina.com.cn">新浪微博</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://ss16.sinaimg.cn/thumbnail/62914aabt8fdc6a2f6c0f&690</thumbnail_pic>
      <bmiddle_pic>http://ss16.sinaimg.cn/bmiddle/62914aabt8fdc6a2f6c0f&690</bmiddle_pic>
      <original_pic>http://ss16.sinaimg.cn/orignal/62914aabt8fdc6a2f6c0f&690</original_pic>
      <user>
        <id>1653689003</id>
        <screen_name>新周刊</screen_name>
        <name>新周刊</name>
        <province>44</province>
        <city>1</city>
        <location>广东 广州</location>
        <description>《新周刊》,中国最新锐的时事生活周刊:观点供应商,视觉开发商,资讯整合商,传媒运营商。</description>
        <url>http://blog.sina.com.cn/xinzhoukan</url>
        <profile_image_url>http://tp4.sinaimg.cn/1653689003/50/1283204286</profile_image_url>
        <domain>neweekly</domain>
        <gender>m</gender>
        <followers_count>559667</followers_count>
        <friends_count>203</friends_count>
        <statuses_count>5748</statuses_count>
        <favourites_count>10</favourites_count>
        <created_at>Wed Oct 14 00:00:00 +0800 2009</created_at>
        <following>false</following>
        <verified>true</verified>
        <allow_all_act_msg>false</allow_all_act_msg>
        <geo_enabled>false</geo_enabled>
      </user>
    </retweeted_status>
  </status>
</user>

JSON示例:

 {
   "id":11075,
   "screen_name":"name_11075",
   "name":"name_11075",
   "province":"0",
   "city":"0",
   "location":"",
   "description":"",
   "url":"",
   "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0",
   "domain":"11075",
   "followers_count":28,
   "friends_count":50,
   "statuses_count":29,
   "favourites_count":0,
   "created_at":"Thu Jan 01 08:00:00 +0800 1970",
   "following":false,
   "geo_enabled":false,
   "verified":true,
   "status":
         {"created_at":"Thu Jan 07 17:36:07 +0800 2010",
          "id":142309,
          "text":"要查询的微博ID",
          "source":"<a id=\"0\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>",
          "favorited":false,
          "truncated":false,
          "in_reply_to_status_id":"",
          "in_reply_to_user_id":"",
          "in_reply_to_screen_name":"",
          "geo":null}
  }

字段说明 - 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标示,是否微博认证用户

使用示例

  • xml:

curl -u user:password -d "" http://api.t.sina.com.cn/friendships/create/timyang.xml

  • json:

curl -u user:password -d "" http://api.t.sina.com.cn/friendships/create/timyang.json

Java示例

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

package weibo4j.examples;

import weibo4j.Weibo;
import weibo4j.WeiboException;

public class CreateFriendship {

	/**
	 * 关注某用户 
	 * @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).createFriendship(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/create
//关注某用户
$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->follow($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('New Friend:'.$msg['screen_name']);
}