微博开放平台
微连接
移动应用
网站接入
电商服务商
电商商家
数据服务
数据服务
合作伙伴
微博支付
轻应用
粉丝服务
文档
推广
我的应用
登录
weibo
开发文档
首页
平台政策与指引
概述
平台公约
新手指南
开发者协议
应用运营管理规范
微连接分级管理办法
应用审核产品指南
应用安全开发注意事项
平台应用设计规范
微服务接入指南
微博登录接入
用微博帐号登录
授权机制
移动应用接入
移动应用介绍
移动应用SSO授权
微博Deep Link
媒体接入平台
头条文章开放接口
视频上传开放接口
电商接入平台
电商服务商接入
电商商家端接入
电商平台能力接口
粉丝服务平台
粉丝服务平台
新手接入指南
微信开发者迁移指南
接收消息
发送消息
自定义菜单
用户管理
生成带参数的二维码
Fans Service Platform
商业接口
商业数据接入指南
订阅服务手册(中文版)
订阅服务手册(英文版)
商业接口-REST API
商业数据常见问题
网站接入
网站接入介绍
微博API
微博API
接口访问频次权限
资源下载
SDK
微博标识下载
常见问题
联系我们
工具箱
链入页面
链出更改
特殊页面
查看源代码
跳转到:
导航
,
搜索
根据下列原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
{{api_desc2| uri=friendships/create| desc=关注一个用户。关注成功则返回关注人的资料,目前的最多关注2000人。| format=XML/JSON| httpMethod=POST| 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=1658122963"| result= ===XML示例=== <pre> <?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> </pre> ===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" : [ ], "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" : "北京 朝阳区" } </pre> {{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 * 关注不存在的ID返回400 *<font style="color:red">此接口仅针对微博类客户端开放,非微博类客户端应用不开放此接口权限。</font>| * 如果已经关注了此人,则返回http 403的状态。| otherInfo= ===Java示例=== 请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br> 代码示例如下: 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 | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br> 代码示例如下: <pre> //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']); } </pre> }}
该页面使用的模板:
模板:Api args
(
查看源代码
)
模板:Api args colspan
(
查看源代码
)
模板:Api desc2
(
查看源代码
)
模板:Param status
(
查看源代码
)
模板:Param user
(
查看源代码
)
返回到
Friendships/create
。
反馈
分享
顶部