Friendships/create

跳转到: 导航, 搜索
(返回结果)
 
(未显示3个用户的9个中间版本)
第1行: 第1行:
== friendships/create ==
+
{{api_desc2|
关注一个用户。成功则返回关注人的资料,目前的最多关注2000人,失败则返回一条字符串的说明。如果已经关注了此人,则返回http 403的状态.
+
uri=friendships/create|
 
+
desc=关注一个用户。关注成功则返回关注人的资料,目前的最多关注2000人。|
=== URL===
+
format=XML/JSON|
http://api.t.sina.com.cn/friendships/create/id.format
+
httpMethod=POST|
+
needAuth=true|
===格式===
+
rateLimit=true|
xml, json
+
params={{api_args|:id|false|int64/string|要关注的用户ID(int64)或者微博昵称(string),该参数是一个REST风格的参数。用法见注意事项}}
+
{{api_args|user_id|false|int64|要关注的用户ID,为了避免用户的ID与微博昵称相同而产生混淆的情况,推荐使用该参数。}}
=== HTTP请求方式===
+
{{api_args|screen_name|false|string|要关注的用户微博昵称,为了避免用户的ID与微博昵称相同而产生混淆的情况,推荐使用该参数。}}
POST
+
{{api_args_colspan|1=<font style="color:#ee3333">:id、user_id、screen_name这三个参数必填其一。</font>}}|
+
getParam=|
===是否需要身份验证===
+
postParam=-d "user_id=1658122963"|
true
+
result=
 
+
===XML示例===
===请求参数===
+
====必选参数(至少选一个)====
+
* 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示例:
+
 
<pre>
 
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<user>
 
<user>
   <id>1266321801</id>
+
   <id>1658122963</id>
   <screen_name>姚晨</screen_name>
+
   <screen_name>zhangwei217245</screen_name>
   <name>姚晨</name>
+
   <name>zhangwei217245</name>
 
   <province>11</province>
 
   <province>11</province>
 
   <city>5</city>
 
   <city>5</city>
 
   <location>北京 朝阳区</location>
 
   <location>北京 朝阳区</location>
   <description>一颗很逊的卤蛋。</description>
+
   <description>ABCDE</description>
   <url>http://blog.sina.com.cn/yaochen</url>
+
   <url/>
   <profile_image_url>http://tp2.sinaimg.cn/1266321801/50/1283203855</profile_image_url>
+
   <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url>
   <domain>yaochen</domain>
+
   <domain>zhangwei217245</domain>
   <gender>f</gender>
+
   <gender>m</gender>
   <followers_count>2786967</followers_count>
+
   <followers_count>25</followers_count>
   <friends_count>561</friends_count>
+
   <friends_count>46</friends_count>
   <statuses_count>2148</statuses_count>
+
   <statuses_count>119</statuses_count>
   <favourites_count>10</favourites_count>
+
   <favourites_count>3</favourites_count>
   <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at>
+
   <created_at>Tue Nov 03 00:00:00 +0800 2009</created_at>
 
   <following>false</following>
 
   <following>false</following>
   <verified>true</verified>
+
   <verified>false</verified>
 
   <allow_all_act_msg>false</allow_all_act_msg>
 
   <allow_all_act_msg>false</allow_all_act_msg>
   <geo_enabled>false</geo_enabled>
+
   <geo_enabled>true</geo_enabled>
 
   <status>
 
   <status>
     <created_at>Fri Sep 10 09:47:00 +0800 2010</created_at>
+
     <created_at>Mon Dec 06 13:47:10 +0800 2010</created_at>
     <id>2465393025</id>
+
     <id>4120818179</id>
     <text>愿我永远不要失去给他人带来快乐的能力,因为失去它,自己也不可能再拥有快乐。</text>
+
     <text>一个存储系统~~~ 姑且认为是标题党</text>
 
     <source>
 
     <source>
       <a href="http://news.sina.com.cn/wap/wbclient.html#3">iPhone客户端</a>
+
       <a href="http://t.sina.com.cn">新浪微博</a>
 
     </source>
 
     </source>
 
     <favorited>false</favorited>
 
     <favorited>false</favorited>
第68行: 第51行:
 
     <in_reply_to_screen_name/>
 
     <in_reply_to_screen_name/>
 
     <retweeted_status>
 
     <retweeted_status>
       <created_at>Fri Sep 10 08:00:03 +0800 2010</created_at>
+
       <created_at>Mon Dec 06 11:09:56 +0800 2010</created_at>
       <id>2463041144</id>
+
       <id>4117314145</id>
       <text>许多人知道如何享乐,却不知道自己从何时起已不再向别人提供欢乐。(BY阿瑟·赫尔普斯)早安,各位。</text>
+
       <text>一个存储系统,从高到底设计非常人性,太有爱了!(Via:http://sinaurl.cn/hb5abi)</text>
 
       <source>
 
       <source>
 
         <a href="http://t.sina.com.cn">新浪微博</a>
 
         <a href="http://t.sina.com.cn">新浪微博</a>
第80行: 第63行:
 
       <in_reply_to_user_id/>
 
       <in_reply_to_user_id/>
 
       <in_reply_to_screen_name/>
 
       <in_reply_to_screen_name/>
       <thumbnail_pic>http://ss16.sinaimg.cn/thumbnail/62914aabt8fdc6a2f6c0f&amp;690</thumbnail_pic>
+
       <thumbnail_pic>http://ww2.sinaimg.cn/thumbnail/69b7fcafgw6dc2pwus9ekg.gif</thumbnail_pic>
       <bmiddle_pic>http://ss16.sinaimg.cn/bmiddle/62914aabt8fdc6a2f6c0f&amp;690</bmiddle_pic>
+
       <bmiddle_pic>http://ww2.sinaimg.cn/bmiddle/69b7fcafgw6dc2pwus9ekg.gif</bmiddle_pic>
       <original_pic>http://ss16.sinaimg.cn/orignal/62914aabt8fdc6a2f6c0f&amp;690</original_pic>
+
       <original_pic>http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif</original_pic>
 
       <user>
 
       <user>
         <id>1653689003</id>
+
         <id>1773665455</id>
         <screen_name>新周刊</screen_name>
+
         <screen_name>MADBRIEF</screen_name>
         <name>新周刊</name>
+
         <name>MADBRIEF</name>
         <province>44</province>
+
         <province>33</province>
         <city>1</city>
+
         <city>3</city>
         <location>广东 广州</location>
+
         <location>浙江 温州</location>
         <description>《新周刊》,中国最新锐的时事生活周刊:观点供应商,视觉开发商,资讯整合商,传媒运营商。</description>
+
         <description>疯狂简报 | MADBRIEF.Com 关于创意与生意</description>
         <url>http://blog.sina.com.cn/xinzhoukan</url>
+
         <url>http://www.madbrief.com/</url>
         <profile_image_url>http://tp4.sinaimg.cn/1653689003/50/1283204286</profile_image_url>
+
         <profile_image_url>http://tp4.sinaimg.cn/1773665455/50/1290503872/1</profile_image_url>
         <domain>neweekly</domain>
+
         <domain>madbrief</domain>
 
         <gender>m</gender>
 
         <gender>m</gender>
         <followers_count>559667</followers_count>
+
         <followers_count>929</followers_count>
         <friends_count>203</friends_count>
+
         <friends_count>565</friends_count>
         <statuses_count>5748</statuses_count>
+
         <statuses_count>1581</statuses_count>
         <favourites_count>10</favourites_count>
+
         <favourites_count>0</favourites_count>
         <created_at>Wed Oct 14 00:00:00 +0800 2009</created_at>
+
         <created_at>Mon Jul 12 00:00:00 +0800 2010</created_at>
 
         <following>false</following>
 
         <following>false</following>
         <verified>true</verified>
+
         <verified>false</verified>
 
         <allow_all_act_msg>false</allow_all_act_msg>
 
         <allow_all_act_msg>false</allow_all_act_msg>
         <geo_enabled>false</geo_enabled>
+
         <geo_enabled>true</geo_enabled>
 
       </user>
 
       </user>
 +
      <annotations/>
 
     </retweeted_status>
 
     </retweeted_status>
 +
    <annotations/>
 
   </status>
 
   </status>
 
</user>
 
</user>
 
</pre>
 
</pre>
JSON示例:
+
===JSON示例===
 +
<pre>
 +
{
 +
    "name" : "zhangwei217245",
 +
    "domain" : "zhangwei217245",
 +
    "geo_enabled" : true,
 +
    "followers_count" : 25,
 +
    "statuses_count" : 119,
 +
    "favourites_count" : 3,
 +
    "city" : "5",
 +
    "description" : "ABCDE",
 +
    "verified" : false,
 +
    "status" :
 +
    {
 +
        "created_at" : "Mon Dec 06 13:47:10 +0800 2010",
 +
        "text" : "一个存储系统~~~ 姑且认为是标题党",
 +
        "truncated" : false,
 +
        "retweeted_status" :
 +
        {
 +
            "created_at" : "Mon Dec 06 11:09:56 +0800 2010",
 +
            "text" : "一个存储系统,从高到底设计非常人性,太有爱了!(Via:http://sinaurl.cn/hb5abi)",
 +
            "bmiddle_pic" : "http://ww2.sinaimg.cn/bmiddle/69b7fcafgw6dc2pwus9ekg.gif",
 +
            "original_pic" : "http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif",
 +
            "truncated" : false,
 +
            "in_reply_to_status_id" : "",
 +
            "annotations" :
 +
            [
  
  {
+
            ],
    "id":11075,
+
            "in_reply_to_screen_name" : "",
    "screen_name":"name_11075",
+
            "geo" : null,
    "name":"name_11075",
+
            "user" :
    "province":"0",
+
            {
    "city":"0",
+
                "name" : "MADBRIEF",
    "location":"",
+
                "domain" : "madbrief",
    "description":"",
+
                "geo_enabled" : true,
    "url":"",
+
                "followers_count" : 929,
    "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0",
+
                "statuses_count" : 1581,
    "domain":"11075",
+
                "favourites_count" : 0,
    "followers_count":28,
+
                "city" : "3",
    "friends_count":50,
+
                "description" : "疯狂简报 | MADBRIEF.Com 关于创意与生意",
    "statuses_count":29,
+
                "verified" : false,
    "favourites_count":0,
+
                "id" : 1773665455,
    "created_at":"Thu Jan 01 08:00:00 +0800 1970",
+
                "gender" : "m",
    "following":false,
+
                "friends_count" : 565,
    "geo_enabled":false,
+
                "screen_name" : "MADBRIEF",
    "verified":true,
+
                "allow_all_act_msg" : false,
    "status":
+
                "following" : false,
          {"created_at":"Thu Jan 07 17:36:07 +0800 2010",
+
                "url" : "http://www.madbrief.com/",
          "id":142309,
+
                "profile_image_url" : "http://tp4.sinaimg.cn/1773665455/50/1290503872/1",
          "text":"要查询的微博ID",
+
                "created_at" : "Mon Jul 12 00:00:00 +0800 2010",
          "source":"<a id=\"0\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>",
+
                "province" : "33",
          "favorited":false,
+
                "location" : "浙江 温州"
          "truncated":false,
+
            },
          "in_reply_to_status_id":"",
+
            "favorited" : false,
          "in_reply_to_user_id":"",
+
            "thumbnail_pic" : "http://ww2.sinaimg.cn/thumbnail/69b7fcafgw6dc2pwus9ekg.gif",
          "in_reply_to_screen_name":"",
+
            "in_reply_to_user_id" : "",
          "geo":null}
+
            "id" : 4117314145,
  }
+
            "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
 +
        },
 +
        "in_reply_to_status_id" : "",
 +
        "annotations" :  
 +
        [
 +
 
 +
        ],
 +
        "in_reply_to_screen_name" : "",
 +
        "geo" : null,
 +
        "favorited" : false,
 +
        "in_reply_to_user_id" : "",
 +
        "id" : 4120818179,
 +
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
 +
    },
 +
    "id" : 1658122963,
 +
    "gender" : "m",
 +
    "friends_count" : 46,
 +
    "screen_name" : "zhangwei217245",
 +
    "allow_all_act_msg" : false,
 +
    "following" : false,
 +
    "url" : "",
 +
    "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213",
 +
    "created_at" : "Tue Nov 03 00:00:00 +0800 2009",
 +
    "province" : "11",
 +
    "location" : "北京 朝阳区"
 +
}
 +
</pre>
 
{{param_user}}
 
{{param_user}}
 
+
{{param_status}}|
===使用示例===
+
useAge=
 
+
* :id为REST风格的参数,使用该参数的URL为:<br/> http://api.t.sina.com.cn/friendships/create/:id.format <br/> 使用示例如下:<br/> http://api.t.sina.com.cn/friendships/create/1658122963.xml?source=appkey<br/>http://api.t.sina.com.cn/friendships/create/zhangwei217245.json?source=appkey
* xml:
+
* 关注不存在的ID返回400
 
+
*<font style="color:red">此接口仅针对微博类客户端开放,非微博类客户端应用不开放此接口权限。</font>|
curl -u user:password -d "" http://api.t.sina.com.cn/friendships/create/timyang.xml
+
* 如果已经关注了此人,则返回http 403的状态。|
 
+
otherInfo=
* json:
+
===Java示例===
 
+
curl -u user:password -d "" http://api.t.sina.com.cn/friendships/create/timyang.json
+
 
+
====Java示例====
+
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
代码示例如下:
 
代码示例如下:
第190行: 第223行:
 
  }
 
  }
 
  }
 
  }
====PHP示例====
+
===PHP示例===
 
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
 
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
 
代码示例如下:
 
代码示例如下:
第215行: 第248行:
 
}
 
}
 
</pre>
 
</pre>
 +
}}

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

目录

friendships/create

关注一个用户。关注成功则返回关注人的资料,目前的最多关注2000人。

URL

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

支持格式

XML/JSON

HTTP请求方式

POST

是否需要登录

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>1658122963</id>
  <screen_name>zhangwei217245</screen_name>
  <name>zhangwei217245</name>
  <province>11</province>
  <city>5</city>
  <location>北京 朝阳区</location>
  <description>ABCDE</description>
  <url/>
  <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url>
  <domain>zhangwei217245</domain>
  <gender>m</gender>
  <followers_count>25</followers_count>
  <friends_count>46</friends_count>
  <statuses_count>119</statuses_count>
  <favourites_count>3</favourites_count>
  <created_at>Tue Nov 03 00:00:00 +0800 2009</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 13:47:10 +0800 2010</created_at>
    <id>4120818179</id>
    <text>一个存储系统~~~ 姑且认为是标题党</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/>
    <retweeted_status>
      <created_at>Mon Dec 06 11:09:56 +0800 2010</created_at>
      <id>4117314145</id>
      <text>一个存储系统,从高到底设计非常人性,太有爱了!(Via:http://sinaurl.cn/hb5abi)</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://ww2.sinaimg.cn/thumbnail/69b7fcafgw6dc2pwus9ekg.gif</thumbnail_pic>
      <bmiddle_pic>http://ww2.sinaimg.cn/bmiddle/69b7fcafgw6dc2pwus9ekg.gif</bmiddle_pic>
      <original_pic>http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif</original_pic>
      <user>
        <id>1773665455</id>
        <screen_name>MADBRIEF</screen_name>
        <name>MADBRIEF</name>
        <province>33</province>
        <city>3</city>
        <location>浙江 温州</location>
        <description>疯狂简报 | MADBRIEF.Com 关于创意与生意</description>
        <url>http://www.madbrief.com/</url>
        <profile_image_url>http://tp4.sinaimg.cn/1773665455/50/1290503872/1</profile_image_url>
        <domain>madbrief</domain>
        <gender>m</gender>
        <followers_count>929</followers_count>
        <friends_count>565</friends_count>
        <statuses_count>1581</statuses_count>
        <favourites_count>0</favourites_count>
        <created_at>Mon Jul 12 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>
      </user>
      <annotations/>
    </retweeted_status>
    <annotations/>
  </status>
</user>

JSON示例

{
    "name" : "zhangwei217245",
    "domain" : "zhangwei217245",
    "geo_enabled" : true,
    "followers_count" : 25,
    "statuses_count" : 119,
    "favourites_count" : 3,
    "city" : "5",
    "description" : "ABCDE",
    "verified" : false,
    "status" : 
    {
        "created_at" : "Mon Dec 06 13:47:10 +0800 2010",
        "text" : "一个存储系统~~~ 姑且认为是标题党",
        "truncated" : false,
        "retweeted_status" : 
        {
            "created_at" : "Mon Dec 06 11:09:56 +0800 2010",
            "text" : "一个存储系统,从高到底设计非常人性,太有爱了!(Via:http://sinaurl.cn/hb5abi)",
            "bmiddle_pic" : "http://ww2.sinaimg.cn/bmiddle/69b7fcafgw6dc2pwus9ekg.gif",
            "original_pic" : "http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif",
            "truncated" : false,
            "in_reply_to_status_id" : "",
            "annotations" : 
            [

            ],
            "in_reply_to_screen_name" : "",
            "geo" : null,
            "user" : 
            {
                "name" : "MADBRIEF",
                "domain" : "madbrief",
                "geo_enabled" : true,
                "followers_count" : 929,
                "statuses_count" : 1581,
                "favourites_count" : 0,
                "city" : "3",
                "description" : "疯狂简报 | MADBRIEF.Com 关于创意与生意",
                "verified" : false,
                "id" : 1773665455,
                "gender" : "m",
                "friends_count" : 565,
                "screen_name" : "MADBRIEF",
                "allow_all_act_msg" : false,
                "following" : false,
                "url" : "http://www.madbrief.com/",
                "profile_image_url" : "http://tp4.sinaimg.cn/1773665455/50/1290503872/1",
                "created_at" : "Mon Jul 12 00:00:00 +0800 2010",
                "province" : "33",
                "location" : "浙江 温州"
            },
            "favorited" : false,
            "thumbnail_pic" : "http://ww2.sinaimg.cn/thumbnail/69b7fcafgw6dc2pwus9ekg.gif",
            "in_reply_to_user_id" : "",
            "id" : 4117314145,
            "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
        },
        "in_reply_to_status_id" : "",
        "annotations" : 
        [

        ],
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "favorited" : false,
        "in_reply_to_user_id" : "",
        "id" : 4120818179,
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
    },
    "id" : 1658122963,
    "gender" : "m",
    "friends_count" : 46,
    "screen_name" : "zhangwei217245",
    "allow_all_act_msg" : false,
    "following" : false,
    "url" : "",
    "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213",
    "created_at" : "Tue Nov 03 00:00:00 +0800 2009",
    "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 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']);
}
文档更新时间: 2015-06-24