新浪微博授权认证过程
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
一、授權(quán)認證
1、請求用戶授權(quán)Token
URL: https://api.weibo.com/oauth2/authorize
HTTP請求方式:GET/POST
請求參數(shù)
必選 類型及范圍 說明
client_id true string 申請應(yīng)用時分配的AppKey。
redirect_uri true string 授權(quán)回調(diào)地址,站外應(yīng)用需與設(shè)置的回調(diào)地址一致,站內(nèi)應(yīng)用需填寫canvas page的地址。
返回值字段 字段類型 字段說明
code string 用于調(diào)用access_token,接口獲取授權(quán)后的access token。
state string 如果傳遞參數(shù),會回傳該參數(shù)。
示例
//請求
https://api.weibo.com/oauth2/authorize?client_id=123050457758183&redirect_uri=http://www.example.com/response&response_type=code
//同意授權(quán)后會重定向
http://www.example.com/response&code=CODE
2、獲取授權(quán)過的Access Token
URL :https://api.weibo.com/oauth2/access_token
HTTP請求方式 :POST
請求參數(shù)
必選 類型及范圍 說明
client_id true string 申請應(yīng)用時分配的AppKey。
client_secret true string 申請應(yīng)用時分配的AppSecret。
grant_type true string 請求的類型,填寫authorization_code
grant_type為authorization_code時
必選 類型及范圍 說明
code true string 調(diào)用authorize獲得的code值。
redirect_uri true string 回調(diào)地址,需需與注冊應(yīng)用里的回調(diào)地址一致。
返回數(shù)據(jù)
{
“access_token”: “ACCESS_TOKEN”,
“expires_in”: 1234,
“remind_in”:”798114”,
“uid”:”12341234”
}
返回值字段 字段類型 字段說明
access_token string 用于調(diào)用access_token,接口獲取授權(quán)后的access token。
expires_in string access_token的生命周期,單位是秒數(shù)。
remind_in string access_token的生命周期(該參數(shù)即將廢棄,開發(fā)者請使用expires_in)。
uid string 當前授權(quán)用戶的UID。
二、 微博的讀取
1、statuses/public_timeline
返回最新的公共微博
URL
https://api.weibo.com/2/statuses/public_timeline.json
支持格式
JSON
HTTP請求方式
GET
是否需要登錄
是
關(guān)于登錄授權(quán),參見 如何登錄授權(quán)
訪問授權(quán)限制
訪問級別:普通接口
頻次限制:是
關(guān)于頻次限制,參見 接口訪問權(quán)限說明
請求參數(shù)
必選 類型及范圍 說明
source false string 采用OAuth授權(quán)方式不需要此參數(shù),其他授權(quán)方式為必填參數(shù),數(shù)值為應(yīng)用的AppKey。
access_token false string 采用OAuth授權(quán)方式為必填參數(shù),其他授權(quán)方式不需要此參數(shù),OAuth授權(quán)后獲得。
count false int 單頁返回的記錄條數(shù),默認為50。
page false int 返回結(jié)果的頁碼,默認為1。
base_app false int 是否只獲取當前應(yīng)用的數(shù)據(jù)。0為否(所有數(shù)據(jù)),1為是(僅當前應(yīng)用),默認為0。
注意事項
無
調(diào)用樣例及調(diào)試工具
API測試工具
返回結(jié)果
JSON示例
{
“statuses”: [
{
“created_at”: “Tue May 31 17:46:55 +0800 2011”,
“id”: 11488058246,
“text”: “求關(guān)注。”,
“source”: “新浪微博“,
“favorited”: false,
“truncated”: false,
“in_reply_to_status_id”: “”,
“in_reply_to_user_id”: “”,
“in_reply_to_screen_name”: “”,
“geo”: null,
“mid”: “5612814510546515491”,
“reposts_count”: 8,
“comments_count”: 9,
“annotations”: [],
“user”: {
“id”: 1404376560,
“screen_name”: “zaku”,
“name”: “zaku”,
“province”: “11”,
“city”: “5”,
“l(fā)ocation”: “北京 朝陽區(qū)”,
“description”: “人生五十年,乃如夢如幻;有生斯有死,壯士復(fù)何憾。”,
“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,
“remark”: “”,
“geo_enabled”: true,
“verified”: false,
“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
}
},
..
],
“previous_cursor”: 0,
“next_cursor”: 11488013766,
“total_number”: 81655
}
關(guān)于錯誤返回值與錯誤代碼,參見 錯誤代碼說明
返回字段說明
返回值字段 字段類型 字段說明
created_at string 微博創(chuàng)建時間
id int64 微博ID
mid int64 微博MID
idstr string 字符串型的微博ID
text string 微博信息內(nèi)容
source string 微博來源
favorited boolean 是否已收藏,true:是,false:否
truncated boolean 是否被截斷,true:是,false:否
in_reply_to_status_id string (暫未支持)回復(fù)ID
in_reply_to_user_id string (暫未支持)回復(fù)人UID
in_reply_to_screen_name string (暫未支持)回復(fù)人昵稱
thumbnail_pic string 縮略圖片地址,沒有時不返回此字段
bmiddle_pic string 中等尺寸圖片地址,沒有時不返回此字段
original_pic string 原始圖片地址,沒有時不返回此字段
geo object 地理信息字段 詳細
user object 微博作者的用戶信息字段 詳細
retweeted_status object 被轉(zhuǎn)發(fā)的原微博信息字段,當該微博為轉(zhuǎn)發(fā)微博時返回 詳細
reposts_count int 轉(zhuǎn)發(fā)數(shù)
comments_count int 評論數(shù)
attitudes_count int 表態(tài)數(shù)
mlevel int 暫未支持
visible object 微博的可見性及指定可見分組信息。該object中type取值,0:普通微博,1:私密微博,3:指定分組微博,4:密友微博;list_id為分組的組號
pic_ids object 微博配圖ID。多圖時返回多圖ID,用來拼接圖片url。用返回字段thumbnail_pic的地址配上該返回字段的圖片ID,即可得到多個圖片url。
ad object array 微博流內(nèi)的推廣微博ID
轉(zhuǎn)載于:https://my.oschina.net/xiuer/blog/1068598
總結(jié)
以上是生活随笔為你收集整理的新浪微博授权认证过程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Python的管理系统(附源码)
- 下一篇: UVA - 10061 How many