Live/im/api/en

跳转到: 导航, 搜索
第1行: 第1行:
 +
==Summarize==
 +
To use the APIs of Sina Weibo open platform, you have to register a application first. We will provide a unique App Key and App Secret for every application. The Key and Secret has a same usage of other public key/private key in other protocol. You can use the programming language you like to sign every API call with the Key and Secret, to authenticate the access for Sina Weibo open platform.
  
== 概述 ==
 
  
 +
Web application should fully use OAuth for user authentication. Desktop and mobile application should use OAuth as well, but Basic Auth, a simple method that directly use the user name and password is also accepted for desktop application. Details can be found at  authorization mechanism statement
 +
Currently, OAuth 1.0a is used for Sina Weibo open platform.
  
微博与接入微博的第三方合作的一种模式是“服务端同步”,即微博直播互动系统和第三方互动系统之间做消息同步,从而实现消息共享的效果。发送消息接口和拉取消息接口(主动拉取和回调拉取)提供第三方的消息同步到微博的功能。
 
  
== 互动上行 ==
+
==OAuth Basic Workflow==
 +
OAuth request loop can be separated by 4 steps:
 +
{{center|http://open.sinaimg.cn/oauth/oauth_flowchart.jpg}}
 +
OAuth provides two authentication method: query-string and http headers. We sugguest Http header method.
  
'''说明'''
+
===Request the signature===
 +
All the OAuth request use the same algorithm to generate the signature base string and signature.
 +
Base string is a URL encode of a string that join http method name, URL and request parameter with &. Then, sort all the request parameter including parameter in POST method by the letter, replace = with %3D, join all the strings with %26 as a separating character.
 +
This algorithm can be simply descripted as :
  
直播用户上行评论接口
+
<pre>
 +
httpMethod + "&" +
 +
  url_encode(  base_uri ) + "&" +
 +
  sorted_query_params.each  { | k, v |
 +
      url_encode ( k ) + "%3D" +
 +
      url_encode ( v )
 +
  }.join("%26")
 +
</pre>
 +
No matter which type of OAuth 1.0 requested, the generating method of BASE STRING is not changed.
 +
Sina Weibo requires that OAuth request is signed in <b>HMAC-SHA1<b>.
  
 +
===Retrieve the requesttoken===
 +
Retrieving request token is the first step of user authentication. There are two purposes in this step:
 +
1.  Tell Sina Weibo what you want to do.
 +
2.  Tell Sina Weibo what you are going to do in callback
 +
The URL for acquiring request token of Sina Weibo open platform is http://api.t.sina.com.cn/oauth/request_token
 +
Here is an example. We are going to acquire the request token with these parameters:
 +
<pre>
 +
consumer secret - "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98"
 +
oauth_callback - http://localhost:3005/the_dance/process_callback?service_provider_id=11
 +
oauth_consumer_key - GDdmIQH6jhtmLUypg82g
 +
oauth_nonce - QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk
 +
oauth_signature_method - HMAC-SHA1
 +
oauth_timestamp - 1272323042
 +
oauth_version - 1.0
 +
</pre>
 +
First step, generate the BASE STRING with algorithm mentioned. Pay attention that there is a request parameter in the URL of callback. As the parameter is a part of CALLBACK URL, it’s not necessary to use it as a individual parameter. URL should be considered as a string. Generated BASE STRING is
 +
<pre>
 +
POST&https%3A%2F%2Fapi.t.sina.com.cn%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0
 +
</pre>
 +
Our BASE STRING doesn’t include oauth_token and oauth_token_secret, because we haven’t get them yet.
 +
Next, use signing key (App Secret with a & suffix) generate oauth_signature from base string:
 +
<pre>
 +
8wUi7m5HFQy76nowoCThusfgB+Q=
 +
</pre>
 +
Call http://api.t.sina.com.cn/oauth/request_token with http header:
 +
<pre>
 +
OAuth oauth_nonce="QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk", oauth_callback="http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272323042", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_signature="8wUi7m5HFQy76nowoCThusfgB%2BQ%3D", oauth_version="1.0"
 +
</pre>
 +
When server side receive this request, it will return oauth_token, oauth_token_secret and other information. If oauth_callback_confirmed is set to true, it means callback is available now. The return value from server is :
 +
<pre>
 +
oauth_token=8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc&oauth_token_secret=x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA&oauth_callback_confirmed=true
 +
</pre>
 +
Now, oauth_token and oauth_token_secret should be recorded as we need them to get access token.
  
'''URL'''
+
===User Authentication===
 +
In this step, you will get the authentication by the oauth_token you got in last step. In general, WEB application just redirected the to the page, and desktop application requests user authenticates with the URL
 +
The authenticated URL for Sina Weibo open platform is http://api.t.sina.com.cn/oauth/authorize . You should call this API with oauth_token:
 +
http://api.t.sina.com.cn/oauth/authorize?oauth_token=8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc
 +
User should login to Sina Weibo, otherwise, a webpage contained authentication information will be displayed. And user need to confirm the authorization of the application in the page. After that, web application is redirected to the oauth_call you specified, while desktop application will get a PIN code that need to be inputed in your application.
 +
If callback is used, oauth_callback now get the information including oauth_token and oauth_verifier. Eg:
  
https://api.weibo.com/2/liveim/message/sync.json [POST]
+
<pre>
 +
oauth_token=8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc&oauth_verifier=pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY
 +
</pre>
  
 +
===Retrieve access token===
 +
URL for retrieving access token of Sina Weibo open platform is : http://api.t.sina.com.cn/oauth/access_token
 +
Here is Request Parameters:
  
'''支持格式'''
+
<pre>
 +
    oauth_consumer_key - GDdmIQH6jhtmLUypg82g
 +
    oauth_nonce - 9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8
 +
    oauth_signature_method - HMAC-SHA1
 +
    oauth_token - 8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc
 +
    oauth_timestamp - 1272323047
 +
    oauth_verifier - pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY
 +
    oauth_version - 1.0
 +
    oauth_token_secret - x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA
 +
</pre>
 +
Firste, prepare base string (with the method mentioned before)
 +
<pre>
 +
POST&https%3A%2F%2Fapi.t.sina.com.cn%2Foauth%2Faccess_token&oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3D9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323047%26oauth_token%3D8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc%26oauth_verifier%3DpDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY%26oauth_version%3D1.0
 +
</pre>
 +
Join the consumer_secret and oauth_token_secret with & :
 +
<pre>
 +
MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA
 +
</pre>
  
JSON
+
Generated OAuth signature is:
 
+
<pre>
 
+
PUw/dHA4fnlJYM6RhXk5IU/0fCc=
 
+
</pre>
'''是否需要登录'''
+
Then call the specified url with request token, the request header is:
 
+
<pre>
true 登录授权方式,请参见本WIKI内的 [http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E 如何登录授权]
+
OAuth oauth_nonce="9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272323047", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_token="8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc", oauth_verifier="pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY", oauth_signature="PUw%2FdHA4fnlJYM6RhXk5IU%2F0fCc%3D", oauth_version="1.0"
 
+
</pre>
 
+
Sina Weibo open platform return the necessary information including user name, oauth_token/oauth_token_secret (this is access token here). Response content is :
'''请求参数'''
+
<pre>
 
+
oauth_token=819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw&oauth_token_secret=J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA&user_id=819797&screen_name=openapi
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
+
|-
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|参数字段
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段必选
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
+
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
+
{{api_args| access_token|true|string|采用OAuth授权方式为必填参数,OAuth授权后获得}}
+
{{api_args|room_id|true|string|房间id}}
+
{{api_args|ts|true|long|时间戳(1970-01-01 00:00:00 起毫秒数),要求不得延迟2min以上}}
+
{{api_args|msg_type|true|int|消息类型,参见 [http://open.weibo.com/wiki/Live/im/api#.E6.B6.88.E6.81.AF.E7.B1.BB.E5.9E.8B 消息类型]}}
+
{{api_args|content|true|string|消息内容}}
+
{{api_args|uid|true|long|发送者ID}}
+
{{api_args|nickname|true|string|发送者昵称}}
+
{{api_args|avatar|true|string|发送者头像url}}
+
{{api_args|sign|true|string|对sign之外的其他所有参数进行签名的结果 见[http://open.weibo.com/wiki/Live/im/api#.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 签名算法]}}
+
{{api_args|extension|false|string|消息扩展字段 [http://open.weibo.com/wiki/Live/im/api#.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84 参见](json object格式,默认为空json object)}}
+
{{api_args|offset|false|long|发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。}}
+
|}
+
 
+
 
+
 
+
'''返回结果'''
+
 
+
//成功返回
+
<pre class="brush:js">
+
{
+
    "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
+
    "error_msg":""
+
}
+
 
</pre>
 
</pre>
 +
You can use access token to update status now.
  
 
+
===Retrieve user profile===
//失败返回
+
Next, we authenticate user ( If this successes, user profileis returned from server). Here is the parameters for user authentication:
<pre class="brush:js">
+
<pre>
{
+
oauth_consumer_key - GDdmIQH6jhtmLUypg82gる
    "error_code": 91XX,
+
oauth_nonce - oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y
    "error_msg": "xxxxxxxxx"
+
oauth_signature_method - HMAC-SHA1
}
+
oauth_token - 819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw
 +
oauth_timestamp - 1272325550
 +
oauth_version - 1.0
 +
</pre>
 +
Generate header by the BASE STRING alogrithm:
 +
<pre>
 +
POST&https%3A%2F%2Fapi.t.sina.com.cn%2Faccount%2Fverify_credentials&oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3D9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272325550%26oauth_token%3D819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw%26oauth_verifier%3DpDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY%26oauth_version%3D1.0
 
</pre>
 
</pre>
  
== 互动下行—Pull方式 ==
+
Generate signature from the string that joined oauth_comsumer_secret and oauth_token_secret with &.
'''说明'''
+
key is:
  
该接口提供第三方从微博直播互动系统拉取房间消息的功能。
+
<pre>
第三方发起该请求之后,只要不断开连接,该接口会源源不断的推回房间中最新的消息。如果连接意外断开,只要重连之前累计消息数量不超过商定的阈值,消息都会从上次断开的地方继续推送。
+
MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA
 
+
</pre>
 
+
We can call http method now. Generated http header is:
'''URL'''
+
<pre>
 
+
ICuKVLKetCO4axEppJBqOofFg/A=
https://api.weibo.com/2/liveim/message/pull.stream [GET]
+
 
+
 
+
'''支持格式'''
+
 
+
JSON
+
 
+
 
+
'''是否需要登录'''
+
 
+
true 登录授权方式,请参见本WIKI内的[http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E 如何登录授权]
+
 
+
 
+
'''请求参数'''
+
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
+
|-
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|参数字段
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段必选
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
+
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
+
{{api_args| access_token|true|string|采用OAuth授权方式为必填参数,OAuth授权后获得}}
+
{{api_args|room_id|true|string|房间id}}
+
|}
+
 
+
'''返回结果'''
+
返回的消息以JSON的方式推送,推送的数据结构如下,每条消息是一个单独的JSON-OBJECT。
+
 
+
//成功返回
+
<pre class="brush:js">
+
{
+
    "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
+
    "error_msg":"",
+
}
+
{
+
    // 消息体。见附件[数据结构/消息体]
+
}
+
{
+
    // 消息体
+
}
+
...
+
 
</pre>
 
</pre>
 
+
Generated signature is:
 
+
<pre>
//失败返回
+
OAuth oauth_nonce="oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272325550", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_token="819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw", oauth_signature="ICuKVLKetCO4axEppJBqOofFg%2FA%3D", oauth_version="1.0"
<pre class="brush:js">
+
</pre>
 +
Response:
 +
<pre>
 
{
 
{
    "error_code": 91XX,
+
weibo=null,
    "error_msg": "xxxxxxxxx"
+
id=1803876591,
 +
name='loopa',
 +
screenName='loopa',
 +
location='北京 海淀区',
 +
description='2fBAcRG0]8OGRvp',
 +
profileImageUrl='http://tp4.sinaimg.cn/1803876591/50/0',  
 +
url='',
 +
isProtected=false,
 +
followersCount=23,
 +
statusCreatedAt=Mon Sep 27 13:50:14 CST 2010,
 +
statusId=2847344825,
 +
statusText='uhYFQJ[',
 +
statusSource='<a href="" rel="nofollow">微博开放平台接口</a>',
 +
statusTruncated=false,
 +
statusInReplyToStatusId=0,
 +
statusInReplyToUserId=0,
 +
statusFavorited=false,
 +
statusInReplyToScreenName='',
 +
profileBackgroundColor='',
 +
profileTextColor='',
 +
profileLinkColor='',
 +
profileSidebarFillColor='',
 +
profileSidebarBorderColor='',
 +
friendsCount=1,
 +
createdAt=Fri Aug 27 00:00:00 CST 2010,
 +
favouritesCount=0,
 +
utcOffset=-1,
 +
timeZone='',
 +
profileBackgroundImageUrl='',
 +
profileBackgroundTile='',
 +
following=false,
 +
notificationEnabled=false,
 +
statusesCount=8509,
 +
geoEnabled=false,
 +
verified=false
 
}
 
}
 
</pre>
 
</pre>
  
关于错误返回值与错误代码,参见 [http://open.weibo.com/wiki/Live/im/api#.E9.94.99.E8.AF.AF.E7.A0.81.E5.AE.9A.E4.B9.89 错误码定义]
+
===Trips===
 +
Here is some trips
 +
* Use OAuth with HTTP header
 +
* Encrypted all the authenticating data in all steps by SSL
 +
* Use api.t.sina.com.cn, not t.sina.com.cn
 +
* Always explicitly use oauth_callback. Application uses default callback URL. But we suggest using callback explicitly in every call. By the dynamical callback, you can retrieve some useful information. If PIN code is used, callback should be “oob”.
  
== 互动下行—Callback方式 ==
 
'''说明'''
 
  
如果第三方使用的是HTTP Callback的方式接受微博消息,那么第三方也需要提供一个类似[发送消息接口]的接口。要求与那个接口使用相同的参数和返回值。
+
===Post weibo through OAuth===
 +
Now we can post weibo on oauth_token and oauth_token_secret through Statuses/update API. Here is the relative parameters:
 +
* POST body - status=message
 +
* oauth_consumer_key - GDdmIQH6jhtmLUypg82g
 +
* oauth_nonce - oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y
 +
* oauth_signature_method - HMAC-SHA1
 +
* oauth_token - 819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw
 +
* oauth_timestamp - 1272325550
 +
* oauth_version - 1.0
  
 
+
Generated BASE STRING:
'''URL'''
+
<pre>
 
+
POST&http%3A%2F%2Fapi.t.sina.com.cn%2Fstatuses%2Fupdate.json&oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DoElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272325550%26oauth_token%3D819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw%26oauth_version%3D1.0%26status%3D%25E9%2580%259A%25E8%25BF%2587OAuth%25E5%258F%2591%25E9%2580%2581%25E5%25BE%25AE%25E5%258D%259A%25E4%25BF%25A1%25E6%2581%25AF
第三方自定义
+
 
+
 
+
'''支持格式'''
+
 
+
JSON
+
 
+
 
+
'''HTTP请求方式'''
+
 
+
POST
+
 
+
 
+
'''是否需要登录'''
+
 
+
true 登录授权方式,请参见本WIKI内的 [http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E 如何登录授权]
+
 
+
 
+
'''请求参数'''
+
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
+
|-
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|参数字段
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段必选
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
+
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
+
{{api_args| source |true|string|申请应用时分配的AppKey,调用接口时候代表应用的唯一身份(采用OAuth授权方式不需要此参数)}}
+
{{api_args|room_id|true|string|房间id}}
+
{{api_args|ts|true|long|时间戳(1970-01-01 00:00:00 起毫秒数)}}
+
{{api_args|msg_type|true|int|消息类型 1 - 评论消息 2 - 点赞消息}}
+
{{api_args|content|true|string|消息内容}}
+
{{api_args|uid|true|long|发送者ID}}
+
{{api_args|nickname|true|string|发送者昵称}}
+
{{api_args|avatar|true|string|发送者头像url}}
+
{{api_args|sign|true|string|对sign之外的其他所有参数进行签名的结果 见[http://open.weibo.com/wiki/Live/im/api#.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 签名算法]}}
+
{{api_args|extension|false|string|消息扩展字段 [http://open.weibo.com/wiki/Live/im/api#.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84 参见](json object格式,默认为空json object)}}
+
{{api_args|offset|false|long|发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。}}
+
|}
+
 
+
 
+
返回结果
+
 
+
//成功返回
+
<pre class="brush:js">
+
{
+
    "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
+
    "error_msg":""
+
}
+
 
</pre>
 
</pre>
 
+
Generate signature from the string that joined oauth_comsumer_secret and oauth_token_secret with &.
 
+
key is:
//失败返回
+
<pre>
<pre class="brush:js">
+
MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA
 +
</pre>
 +
Generated signature:
 +
<pre>
 +
yOahq5m0YjDDjfjxHaXEsW9D+X0=
 +
</pre>
 +
Send HTTP request with HTTP header:
 +
<pre>
 +
OAuth oauth_nonce="oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272325550", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_token="819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw", oauth_signature="yOahq5m0YjDDjfjxHaXEsW9D%2BX0%3D", oauth_version="1.0"
 +
</pre>
 +
Server response:
 +
<pre>
 
{
 
{
     "error_code": 91XX,
+
     "created_at": "Mon Oct 11 12:00:16 +0800 2010",  
     "error_msg": "xxxxxxxxx"
+
     "favorited": false,
 +
    "geo": null,
 +
    "id": 3034670049,
 +
    "in_reply_to_screen_name": "",
 +
    "in_reply_to_status_id": "",
 +
    "in_reply_to_user_id": "",
 +
    "source": "<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">\u5fae\u535a\u5f00\u653e\u5e73\u53f0\u63a5\u53e3</a>",
 +
    "text": "\u901a\u8fc7OAuth\u53d1\u9001\u5fae\u535a\u4fe1\u606f",
 +
    "truncated": false,
 +
    "user": {
 +
        "allow_all_act_msg": false,
 +
        "city": "8",
 +
        "created_at": "Fri Aug 28 00:00:00 +0800 2009",
 +
        "description": "Blogger\uff0c\u82f9\u679c\u8ff7\uff0cGoogle\u7c89\u3002",
 +
        "domain": "westy",
 +
        "favourites_count": 1,
 +
        "followers_count": 83,
 +
        "following": false,
 +
        "friends_count": 56,
 +
        "gender": "m",
 +
        "geo_enabled": true,
 +
        "id": 1642466141,
 +
        "location": "\u5317\u4eac \u6d77\u6dc0\u533a",
 +
        "name": "huchao",
 +
        "profile_image_url": "http://tp2.sinaimg.cn/1642466141/50/1285424071",
 +
        "province": "11",
 +
        "screen_name": "huchao",
 +
        "statuses_count": 209,
 +
        "url": "http://tuoniao.org",
 +
        "verified": false
 +
    }
 
}
 
}
 
</pre>
 
</pre>
  
== 签名算法==
+
==OAuth libraries and resources==
'''输入:'''
+
:ActionScript/Flash
 +
::oauth-as3 http://code.google.com/p/oauth-as3/
 +
::A flex oauth client  http://www.arcgis.com/home/item.html?id=ff6ffa302ad04a7194999f2ad08250d7
  
- 键值对列表
+
:C/C++
 +
::QTweetLib http://github.com/minimoog/QTweetLib
 +
::libOAuth http://liboauth.sourceforge.net/
  
- 签名时用的appsecret
+
:clojure
 +
::clj-oauth http://github.com/mattrepl/clj-oauth
  
 +
:.net
 +
::oauth-dot-net http://code.google.com/p/oauth-dot-net/
 +
::DotNetOpenAuth http://www.dotnetopenauth.net/
  
'''输出:'''
+
:Erlang
 +
::erlang-oauth http://github.com/tim/erlang-oauth
  
签名结果字符串
+
:java
 +
::Scrible http://github.com/fernandezpablo85/scribe-java
 +
::oauth-signpost http://code.google.com/p/oauth-signpost/
  
 +
:javascript
 +
::oauth in js http://oauth.googlecode.com/svn/code/javascript/
  
'''算法:'''
+
:Objective-C/Cocoa & iPhone programming
 +
::OAuthCore http://bitbucket.org/atebits/oauthcore
 +
::MPOAuthConnection http://code.google.com/p/mpoauthconnection/
 +
::Objective-C OAuth http://oauth.googlecode.com/svn/code/obj-c/
  
- 键值对列表的每一项按照key=value的方式组成该项的字符串,各项的字符串按照对应key的字典序排序(key不相同),然后用半角"&"符号连接形成一个字符串。
+
:Perl
 +
::Net::OAuth http://oauth.googlecode.com/svn/code/perl/
  
- 字符串按照UTF-8编码得到一个字节序列input, secret的字符串按UTF-8编码生成一个字节序列作为key,用hmac-md5的方式计算哈希值的字节序列,哈希值字节序列使用URL-safe-Base64编码,取第6到16个字符作为结果输出。
+
:PHP
 
+
::tmhOAuth http://github.com/themattharris/tmhOAuth
 
+
::oauth-php http://code.google.com/p/oauth-php/
'''算法示例:'''
+
 
+
假设输入是:
+
kv-pair: {"a":"1", "c":"jerry", "b":"tom"}
+
appsecret:  123456
+
 
+
连接成的字符串就是:
+
a=1&b=tom&c=jerry
+
 
+
hmac-md5("a=1&b=tom&c=jerry",123456)
+
输出得到字节数组:[-117, -27, -78, -5, 73, 68, -64, -50, 4, 21, 16, -55, -55, -39, -31, -15]
+
 
+
转成URL-safe的base64字符串:i-Wy-0lEwM4EFRDJydnh8Q==
+
取6到16位(初始位为0)子串,包含第6位,不包含第16位,共10位:lEwM4EFRDJ
+
 
+
 
+
'''签名结果:'''
+
 
+
lEwM4EFRDJ
+
 
+
== 数据结构 ==
+
 
+
'''消息体'''
+
<pre class="brush:js">
+
{
+
    "room_id":string,      // 房间号
+
    "room_sys_id": uint64, // 房间ID (内部)
+
    "msg_type":int,        // 消息类型,见“消息类型说明”
+
    "mid":long,
+
    "sender_info":{
+
        // 发送者的用户信息,见“用户信息”
+
    },
+
    "content":string,      // 消息内容
+
    "extension":string,    // 消息的扩展字段
+
    "offset": long,        // 消息距离视频开始时间间隔,单位ms
+
    "created_at":long      // 时间戳,距离1970-01-01 0:00:00 GMT的毫秒数
+
    // 如果还有其他字段,这些字段在此处继续,相关字段见“各消息类型的额外字段”
+
}
+
 
+
</pre>
+
 
+
'''extension'''
+
 
+
消息类型1~14时,各类消息会有一些该类型特有的字段用于表示一些业务,这些字段会出现在extension中的sys字段里面,结构如下:
+
<pre class="brush:js">
+
extension = {
+
    "sys": {
+
        // 此处出现的字段,见”各类型特有的额外字段“。如果额外字段列表为空,那么"sys"字段可以不存在。
+
    },
+
    // "其它透传的字段"
+
}
+
</pre>
+
 
+
各类型特有的额外字段
+
 
+
<pre class="brush:js">
+
聊天消息,msg_type=1
+
"msg_behavior":uint32  //消息的显示行为  0:默认 1.弹幕
+
+
点赞消息,msg_type=2
+
"praises_count":int    // 当前总赞数
+
"inc_praises":long    // 用户点赞次数
+
+
禁言,msg_type=4
+
"shut_info":{          // 被禁言的用户信息
+
    "shutted_until":uint32  //禁言结束的剩余时间,单位s
+
    "members":[              //被禁言用户列表
+
    {
+
      "uid":uint64          //被禁言用户的UID
+
      "user_system":string  //被禁言用户所属系统
+
    }
+
  ]
+
}
+
+
房间变更,msg_type=11
+
"live_status":int      // 表示直播的状态
+
"room_info": {
+
    // 房间信息体,见“房间信息”
+
}
+
+
加退房间,msg_type=12
+
"exit_or_enter_room":int  // 0:退出 1:进入
+
"room_info": {
+
    // 房间信息体,见“房间信息”
+
}
+
+
增加删除管理员,msg_type=14
+
"admin_info":{            // 被增加或删除的用户信息
+
    "uid":uint64              //管理员的UID
+
    "user_system":string      //管理员所属系统
+
    "type":int              //操作类型 1 增加 2 删除
+
}
+
</pre>
+
  
== 直播接口 ==
+
:Python
请参考[http://open.weibo.com/wiki/Live/api 直播接口文档]
+
::python-oauth2 http://github.com/brosner/python-oauth2
  
== 消息类型 ==
+
:Qt
 +
::qOauth http://github.com/ayoy/qoauth
  
    1 - 聊天消息
+
:Ruby
    2 - 赞消息
+
::Oauth ruby gem http://oauth.rubyforge.org/
    3 - 点亮主播消息
+
    4 - 禁言消息
+
    6 - 公告消息
+
    7 - 分享直播消息
+
    8 - 关注主播消息
+
    11 - 直播变更消息(房间的任何状态变更都会进行push)
+
    12 - 加入/退出房间消息
+
    13 - 打赏消息
+
    14 - 管理员变更消息
+
    100 - 自定义消息类型
+
  
== 错误码定义 ==
+
:Scala
<table class="wiki_table">
+
::DataBinder Dispatch http://dispatch.databinder.net/About
<tr>
+
<th style="width: 10%">错误码</th>
+
<th>错误说明</th>
+
</tr>
+
<tr>
+
<td>9101</td>
+
<td>认证失败</td>
+
</tr>
+
<tr>
+
<td>9102</td>
+
<td>内部错误</td>
+
</tr>
+
<tr>
+
<td>9103</td>
+
<td>数据格式错误</td>
+
</tr>
+
<tr>
+
<td>9104</td>
+
<td>消息内容包含垃圾信息</td>
+
</tr>
+
<tr>
+
<td>9105</td>
+
<td>已经存在</td>
+
</tr>
+
<tr>
+
<td>9106</td>
+
<td>数据不合法。与9103不同的地方在于:9103是数据格式错误, 比如int型的参数传了一个无法解析成int的字符串。而当前错误码表示数据格式本身没有问题, 但是是一个不合法的数据, 比如ID对应的实体不存在</td>
+
</tr>
+
<tr>
+
<td>9107</td>
+
<td>房间不允许发言</td>
+
</tr>
+
<tr>
+
<td>9108</td>
+
<td>用户不存在</td>
+
</tr>
+
<tr>
+
<td>9109</td>
+
<td>房间不存在</td>
+
</tr>
+
<tr>
+
<td>9110</td>
+
<td>token解析错误</td>
+
</tr>
+
<tr>
+
<td>9111</td>
+
<td>房间状态不正确</td>
+
</tr>
+
<tr>
+
<td>9112</td>
+
<td>用户被禁言</td>
+
</tr>
+
<tr>
+
<td>9113</td>
+
<td>当前操作不允许</td>
+
</tr>
+
<tr>
+
<td>1019</td>
+
<td>当前操作不支持</td>
+
</tr>
+
</table>
+

2017年2月24日 (五) 16:18的版本

目录

Summarize

To use the APIs of Sina Weibo open platform, you have to register a application first. We will provide a unique App Key and App Secret for every application. The Key and Secret has a same usage of other public key/private key in other protocol. You can use the programming language you like to sign every API call with the Key and Secret, to authenticate the access for Sina Weibo open platform.


Web application should fully use OAuth for user authentication. Desktop and mobile application should use OAuth as well, but Basic Auth, a simple method that directly use the user name and password is also accepted for desktop application. Details can be found at authorization mechanism statement Currently, OAuth 1.0a is used for Sina Weibo open platform.


OAuth Basic Workflow

OAuth request loop can be separated by 4 steps:

oauth_flowchart.jpg

OAuth provides two authentication method: query-string and http headers. We sugguest Http header method.

Request the signature

All the OAuth request use the same algorithm to generate the signature base string and signature. Base string is a URL encode of a string that join http method name, URL and request parameter with &. Then, sort all the request parameter including parameter in POST method by the letter, replace = with %3D, join all the strings with %26 as a separating character. This algorithm can be simply descripted as :

httpMethod + "&" +
  url_encode(  base_uri ) + "&" +
  sorted_query_params.each  { | k, v |
      url_encode ( k ) + "%3D" +
      url_encode ( v )
  }.join("%26")

No matter which type of OAuth 1.0 requested, the generating method of BASE STRING is not changed. Sina Weibo requires that OAuth request is signed in HMAC-SHA1<b>.

Retrieve the requesttoken

Retrieving request token is the first step of user authentication. There are two purposes in this step: 1. Tell Sina Weibo what you want to do. 2. Tell Sina Weibo what you are going to do in callback The URL for acquiring request token of Sina Weibo open platform is http://api.t.sina.com.cn/oauth/request_token Here is an example. We are going to acquire the request token with these parameters:

consumer secret - "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98"
oauth_callback - http://localhost:3005/the_dance/process_callback?service_provider_id=11
oauth_consumer_key - GDdmIQH6jhtmLUypg82g
oauth_nonce - QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk
oauth_signature_method - HMAC-SHA1
oauth_timestamp - 1272323042
oauth_version - 1.0

First step, generate the BASE STRING with algorithm mentioned. Pay attention that there is a request parameter in the URL of callback. As the parameter is a part of CALLBACK URL, it’s not necessary to use it as a individual parameter. URL should be considered as a string. Generated BASE STRING is

POST&https%3A%2F%2Fapi.t.sina.com.cn%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0

Our BASE STRING doesn’t include oauth_token and oauth_token_secret, because we haven’t get them yet. Next, use signing key (App Secret with a & suffix) generate oauth_signature from base string:

8wUi7m5HFQy76nowoCThusfgB+Q=

Call http://api.t.sina.com.cn/oauth/request_token with http header:

OAuth oauth_nonce="QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk", oauth_callback="http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272323042", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_signature="8wUi7m5HFQy76nowoCThusfgB%2BQ%3D", oauth_version="1.0"

When server side receive this request, it will return oauth_token, oauth_token_secret and other information. If oauth_callback_confirmed is set to true, it means callback is available now. The return value from server is :

oauth_token=8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc&oauth_token_secret=x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA&oauth_callback_confirmed=true

Now, oauth_token and oauth_token_secret should be recorded as we need them to get access token.

User Authentication

In this step, you will get the authentication by the oauth_token you got in last step. In general, WEB application just redirected the to the page, and desktop application requests user authenticates with the URL The authenticated URL for Sina Weibo open platform is http://api.t.sina.com.cn/oauth/authorize . You should call this API with oauth_token: http://api.t.sina.com.cn/oauth/authorize?oauth_token=8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc User should login to Sina Weibo, otherwise, a webpage contained authentication information will be displayed. And user need to confirm the authorization of the application in the page. After that, web application is redirected to the oauth_call you specified, while desktop application will get a PIN code that need to be inputed in your application. If callback is used, oauth_callback now get the information including oauth_token and oauth_verifier. Eg:

oauth_token=8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc&oauth_verifier=pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY

Retrieve access token

URL for retrieving access token of Sina Weibo open platform is : http://api.t.sina.com.cn/oauth/access_token Here is Request Parameters:

    oauth_consumer_key - GDdmIQH6jhtmLUypg82g
    oauth_nonce - 9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8
    oauth_signature_method - HMAC-SHA1
    oauth_token - 8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc
    oauth_timestamp - 1272323047
    oauth_verifier - pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY
    oauth_version - 1.0
    oauth_token_secret - x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA

Firste, prepare base string (with the method mentioned before)

POST&https%3A%2F%2Fapi.t.sina.com.cn%2Foauth%2Faccess_token&oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3D9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323047%26oauth_token%3D8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc%26oauth_verifier%3DpDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY%26oauth_version%3D1.0

Join the consumer_secret and oauth_token_secret with & :

MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA

Generated OAuth signature is:

PUw/dHA4fnlJYM6RhXk5IU/0fCc=

Then call the specified url with request token, the request header is:

OAuth oauth_nonce="9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272323047", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_token="8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc", oauth_verifier="pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY", oauth_signature="PUw%2FdHA4fnlJYM6RhXk5IU%2F0fCc%3D", oauth_version="1.0"

Sina Weibo open platform return the necessary information including user name, oauth_token/oauth_token_secret (this is access token here). Response content is :

oauth_token=819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw&oauth_token_secret=J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA&user_id=819797&screen_name=openapi

You can use access token to update status now.

Retrieve user profile

Next, we authenticate user ( If this successes, user profileis returned from server). Here is the parameters for user authentication:

oauth_consumer_key - GDdmIQH6jhtmLUypg82gる
oauth_nonce - oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y
oauth_signature_method - HMAC-SHA1
oauth_token - 819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw
oauth_timestamp - 1272325550
oauth_version - 1.0

Generate header by the BASE STRING alogrithm:

POST&https%3A%2F%2Fapi.t.sina.com.cn%2Faccount%2Fverify_credentials&oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3D9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272325550%26oauth_token%3D819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw%26oauth_verifier%3DpDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY%26oauth_version%3D1.0

Generate signature from the string that joined oauth_comsumer_secret and oauth_token_secret with &. key is:

MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA

We can call http method now. Generated http header is:

ICuKVLKetCO4axEppJBqOofFg/A=

Generated signature is:

OAuth oauth_nonce="oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272325550", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_token="819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw", oauth_signature="ICuKVLKetCO4axEppJBqOofFg%2FA%3D", oauth_version="1.0"

Response:

{
	weibo=null, 
	id=1803876591, 
	name='loopa', 
	screenName='loopa', 
	location='北京 海淀区', 
	description='2fBAcRG0]8OGRvp', 
	profileImageUrl='http://tp4.sinaimg.cn/1803876591/50/0', 
	url='', 
	isProtected=false, 
	followersCount=23, 
	statusCreatedAt=Mon Sep 27 13:50:14 CST 2010, 
	statusId=2847344825, 
	statusText='uhYFQJ[', 
	statusSource='<a href="" rel="nofollow">微博开放平台接口</a>', 
	statusTruncated=false, 
	statusInReplyToStatusId=0, 
	statusInReplyToUserId=0, 
	statusFavorited=false, 
	statusInReplyToScreenName='', 
	profileBackgroundColor='', 
	profileTextColor='', 
	profileLinkColor='', 
	profileSidebarFillColor='', 
	profileSidebarBorderColor='', 
	friendsCount=1, 
	createdAt=Fri Aug 27 00:00:00 CST 2010, 
	favouritesCount=0, 
	utcOffset=-1, 
	timeZone='', 
	profileBackgroundImageUrl='', 
	profileBackgroundTile='', 
	following=false, 
	notificationEnabled=false, 
	statusesCount=8509, 
	geoEnabled=false, 
	verified=false
}

Trips

Here is some trips

  • Use OAuth with HTTP header
  • Encrypted all the authenticating data in all steps by SSL
  • Use api.t.sina.com.cn, not t.sina.com.cn
  • Always explicitly use oauth_callback. Application uses default callback URL. But we suggest using callback explicitly in every call. By the dynamical callback, you can retrieve some useful information. If PIN code is used, callback should be “oob”.


Post weibo through OAuth

Now we can post weibo on oauth_token and oauth_token_secret through Statuses/update API. Here is the relative parameters:

  • POST body - status=message
  • oauth_consumer_key - GDdmIQH6jhtmLUypg82g
  • oauth_nonce - oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y
  • oauth_signature_method - HMAC-SHA1
  • oauth_token - 819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw
  • oauth_timestamp - 1272325550
  • oauth_version - 1.0

Generated BASE STRING:

POST&http%3A%2F%2Fapi.t.sina.com.cn%2Fstatuses%2Fupdate.json&oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DoElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272325550%26oauth_token%3D819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw%26oauth_version%3D1.0%26status%3D%25E9%2580%259A%25E8%25BF%2587OAuth%25E5%258F%2591%25E9%2580%2581%25E5%25BE%25AE%25E5%258D%259A%25E4%25BF%25A1%25E6%2581%25AF

Generate signature from the string that joined oauth_comsumer_secret and oauth_token_secret with &. key is:

MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA

Generated signature:

yOahq5m0YjDDjfjxHaXEsW9D+X0=

Send HTTP request with HTTP header:

OAuth oauth_nonce="oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272325550", oauth_consumer_key="GDdmIQH6jhtmLUypg82g", oauth_token="819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw", oauth_signature="yOahq5m0YjDDjfjxHaXEsW9D%2BX0%3D", oauth_version="1.0"

Server response:

{
    "created_at": "Mon Oct 11 12:00:16 +0800 2010", 
    "favorited": false, 
    "geo": null, 
    "id": 3034670049, 
    "in_reply_to_screen_name": "", 
    "in_reply_to_status_id": "", 
    "in_reply_to_user_id": "", 
    "source": "<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">\u5fae\u535a\u5f00\u653e\u5e73\u53f0\u63a5\u53e3</a>", 
    "text": "\u901a\u8fc7OAuth\u53d1\u9001\u5fae\u535a\u4fe1\u606f", 
    "truncated": false, 
    "user": {
        "allow_all_act_msg": false, 
        "city": "8", 
        "created_at": "Fri Aug 28 00:00:00 +0800 2009", 
        "description": "Blogger\uff0c\u82f9\u679c\u8ff7\uff0cGoogle\u7c89\u3002", 
        "domain": "westy", 
        "favourites_count": 1, 
        "followers_count": 83, 
        "following": false, 
        "friends_count": 56, 
        "gender": "m", 
        "geo_enabled": true, 
        "id": 1642466141, 
        "location": "\u5317\u4eac \u6d77\u6dc0\u533a", 
        "name": "huchao", 
        "profile_image_url": "http://tp2.sinaimg.cn/1642466141/50/1285424071", 
        "province": "11", 
        "screen_name": "huchao", 
        "statuses_count": 209, 
        "url": "http://tuoniao.org", 
        "verified": false
    }
}

OAuth libraries and resources

ActionScript/Flash
oauth-as3 http://code.google.com/p/oauth-as3/
A flex oauth client http://www.arcgis.com/home/item.html?id=ff6ffa302ad04a7194999f2ad08250d7
C/C++
QTweetLib http://github.com/minimoog/QTweetLib
libOAuth http://liboauth.sourceforge.net/
clojure
clj-oauth http://github.com/mattrepl/clj-oauth
.net
oauth-dot-net http://code.google.com/p/oauth-dot-net/
DotNetOpenAuth http://www.dotnetopenauth.net/
Erlang
erlang-oauth http://github.com/tim/erlang-oauth
java
Scrible http://github.com/fernandezpablo85/scribe-java
oauth-signpost http://code.google.com/p/oauth-signpost/
javascript
oauth in js http://oauth.googlecode.com/svn/code/javascript/
Objective-C/Cocoa & iPhone programming
OAuthCore http://bitbucket.org/atebits/oauthcore
MPOAuthConnection http://code.google.com/p/mpoauthconnection/
Objective-C OAuth http://oauth.googlecode.com/svn/code/obj-c/
Perl
Net::OAuth http://oauth.googlecode.com/svn/code/perl/
PHP
tmhOAuth http://github.com/themattharris/tmhOAuth
oauth-php http://code.google.com/p/oauth-php/
Python
python-oauth2 http://github.com/brosner/python-oauth2
Qt
qOauth http://github.com/ayoy/qoauth
Ruby
Oauth ruby gem http://oauth.rubyforge.org/
Scala
DataBinder Dispatch http://dispatch.databinder.net/About