今天折腾了下新浪的微博登录方式,有了前面的QQ登录开发经验,对于这次的开发就简单得多了。wordpress微博接入,php微博接入,wordpress微博登陆,php微博登陆
一、获取CODE
官方文档:http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E
请求API接口地址:https://api.weibo.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
请求方式GET和POST都可以,GET就简单快捷,根据自己的需求选择吧。
返回格式:https://api.weibo.com/oauth2/www.qqoq.net?code=7dd32dd4895b9029aae27c5339345b0b
二、用CODE获取Access Token
官方文档:http://open.weibo.com/wiki/Oauth2/access_token
请求API接口地址:https://api.weibo.com/oauth2/access_token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=CODE
不同于QQ的GET方式,新浪的Access Token只能通过POST方式请求,所以使用了CURL来模拟POST请求。
返回格式:Array ( [access_token] => 2.00C687XC4C687C687aceC6874C687D [remind_in] => 157679999 [expires_in] => 157679999 [uid] => 2333333333 )
以数组形式返回,返回的数组也与QQ有所差别,多了remind_in和uid,不过也比QQ少做一步,不用再另外去获取openid,这里直接返回个uid了
三、新浪微博获取用户信息
其实单纯作为网站登录的话到第二步已经足够了,这步可以省略,但还是说一下,以/users/show这个API为例。这里可以获取新浪微博用户头像、新浪微博用户名、新浪微博昵称、新浪微博签名描述、位置、出生年月、性别、新浪微博主页等信息。
官方文档:http://open.weibo.com/wiki/2/users/show
请求API接口地址:https://api.weibo.com/2/users/show.json?access_token=xxxxxxxxxxx&uid=111111
以GET方式请求,传入access_token和uid两个参数即可。
返回格式:这个以json格式返回,数据非常多,具体参数请看官方文档
{
"id": 1404376560,
"screen_name": "zaku",
"name": "zaku",
"province": "11",
"city": "5",
"location": "北京 朝阳区",
"description": "人生五十年,乃如梦如幻;有生斯有死,壮士复何憾。",
"url": "http://blog.sina.com.cn/zaku",
"profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",
"domain": "zaku",
"gender": "m",
"followers_count": 1204,
"friends_count": 447,
"statuses_count": 2908,
"favourites_count": 0,
"created_at": "Fri Aug 28 00:00:00 +0800 2009",
"following": false,
"allow_all_act_msg": false,
"geo_enabled": true,
"verified": false,
"status": {
"created_at": "Tue May 24 18:04:53 +0800 2011",
"id": 11142488790,
"text": "我的相机到了。",
"source": "<a href="http://weibo.com" rel="nofollow">新浪微博</a>",
"favorited": false,
"truncated": false,
"in_reply_to_status_id": "",
"in_reply_to_user_id": "",
"in_reply_to_screen_name": "",
"geo": null,
"mid": "5610221544300749636",
"annotations": [],
"reposts_count": 5,
"comments_count": 8
},
"allow_all_comment": true,
"avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1",
"verified_reason": "",
"follow_me": false,
"online_status": 0,
"bi_followers_count": 215
}
wordpress微博接入,php微博接入,wordpress微博登陆,php微博登陆
文章来自QQOQ老萨


最新评论