為什么80%的碼農都做不了架構師?>>> ??
一、授權認證
1、請求用戶授權Token
URL: https://api.weibo.com/oauth2/authorize
HTTP請求方式:GET/POST
請求參數
必選 類型及范圍 說明
client_id true string 申請應用時分配的AppKey。
redirect_uri true string 授權回調地址,站外應用需與設置的回調地址一致,站內應用需填寫canvas page的地址。
返回值字段 字段類型 字段說明
code string 用于調用access_token,接口獲取授權后的access token。
state string 如果傳遞參數,會回傳該參數。
示例
//請求
https://api.weibo.com/oauth2/authorize?client_id=123050457758183&redirect_uri=http://www.example.com/response&response_type=code
//同意授權后會重定向
http://www.example.com/response&code=CODE
2、獲取授權過的Access Token
URL :https://api.weibo.com/oauth2/access_token
HTTP請求方式 :POST
請求參數
必選 類型及范圍 說明
client_id true string 申請應用時分配的AppKey。
client_secret true string 申請應用時分配的AppSecret。
grant_type true string 請求的類型,填寫authorization_code
grant_type為authorization_code時
必選 類型及范圍 說明
code true string 調用authorize獲得的code值。
redirect_uri true string 回調地址,需需與注冊應用里的回調地址一致。
返回數據
{
“access_token”: “ACCESS_TOKEN”,
“expires_in”: 1234,
“remind_in”:”798114”,
“uid”:”12341234”
}
返回值字段 字段類型 字段說明
access_token string 用于調用access_token,接口獲取授權后的access token。
expires_in string access_token的生命周期,單位是秒數。
remind_in string access_token的生命周期(該參數即將廢棄,開發者請使用expires_in)。
uid string 當前授權用戶的UID。
二、 微博的讀取
1、statuses/public_timeline
返回最新的公共微博
URL
https://api.weibo.com/2/statuses/public_timeline.json
支持格式
JSON
HTTP請求方式
GET
是否需要登錄
是
關于登錄授權,參見 如何登錄授權
訪問授權限制
訪問級別:普通接口
頻次限制:是
關于頻次限制,參見 接口訪問權限說明
請求參數
必選 類型及范圍 說明
source false string 采用OAuth授權方式不需要此參數,其他授權方式為必填參數,數值為應用的AppKey。
access_token false string 采用OAuth授權方式為必填參數,其他授權方式不需要此參數,OAuth授權后獲得。
count false int 單頁返回的記錄條數,默認為50。
page false int 返回結果的頁碼,默認為1。
base_app false int 是否只獲取當前應用的數據。0為否(所有數據),1為是(僅當前應用),默認為0。
注意事項
無
調用樣例及調試工具
API測試工具
返回結果
JSON示例
{
“statuses”: [
{
“created_at”: “Tue May 31 17:46:55 +0800 2011”,
“id”: 11488058246,
“text”: “求關注。”,
“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”,
“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,
“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
}
關于錯誤返回值與錯誤代碼,參見 錯誤代碼說明
返回字段說明
返回值字段 字段類型 字段說明
created_at string 微博創建時間
id int64 微博ID
mid int64 微博MID
idstr string 字符串型的微博ID
text string 微博信息內容
source string 微博來源
favorited boolean 是否已收藏,true:是,false:否
truncated boolean 是否被截斷,true:是,false:否
in_reply_to_status_id string (暫未支持)回復ID
in_reply_to_user_id string (暫未支持)回復人UID
in_reply_to_screen_name string (暫未支持)回復人昵稱
thumbnail_pic string 縮略圖片地址,沒有時不返回此字段
bmiddle_pic string 中等尺寸圖片地址,沒有時不返回此字段
original_pic string 原始圖片地址,沒有時不返回此字段
geo object 地理信息字段 詳細
user object 微博作者的用戶信息字段 詳細
retweeted_status object 被轉發的原微博信息字段,當該微博為轉發微博時返回 詳細
reposts_count int 轉發數
comments_count int 評論數
attitudes_count int 表態數
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 微博流內的推廣微博ID