Live/im/api/en

跳转到: 导航, 搜索
(Receive Comments-Callback Mode)
 
(未显示1个用户的9个中间版本)
第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.
 
  
 +
== Overview ==
  
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.
 
  
 +
One of the cooperation mode between weibo and the third-party that access to weibo is server-side synchronization.This mode means doing message synchronization between live interactive system of weibo and interactive system of the third-party to implement message sharing. Send message interface and pull message interface(active pull and callback pull)can synchronize third-party messages to weibo.
  
==OAuth Basic Workflow==
+
== Post Comments ==
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===
+
'''Description'''
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>
+
Post comment of the users to weibo live-im system.
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.
 
  
===User Authentication===
+
'''URL'''
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:
+
  
<pre>
+
https://api.weibo.com/2/liveim/message/sync.json [POST]
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>
+
'''Support Formats'''
    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>
+
  
Generated OAuth signature is:
+
JSON
<pre>
+
 
PUw/dHA4fnlJYM6RhXk5IU/0fCc=
+
 
</pre>
+
 
Then call the specified url with request token, the request header is:
+
'''Authorization'''
<pre>
+
 
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"
+
Required. More details of login authorization, Please refer to this WIKI[http://open.weibo.com/wiki/OAuth/en How to login to authorization]
</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>
+
'''Request parameter'''
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"|Parameter field
 +
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Requires
 +
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"| Field Type
 +
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field description
 +
{{api_args| access_token|true|string|Required parameters when using OAuth authorization mode,obtained after OAuth authorization}}
 +
{{api_args|room_id|true|string|room id}}
 +
{{api_args|ts|true|long|Timestamp(The number of milliseconds from 1970-01-01 00:00:00),cannot delay more than 2min}}
 +
{{api_args|msg_type|true|int|message types, see [http://open.weibo.com/wiki/Live/im/api/en#Message_Type message types]}}
 +
{{api_args|content|true|string|Message content}}
 +
{{api_args|uid|true|long|sender ID}}
 +
{{api_args|nickname|true|string|Sender nickname}}
 +
{{api_args|avatar|true|string|sender avatar url}}
 +
{{api_args|sign|true|string|The result of signing all the parameters other than sign ,See [http://open.weibo.com/wiki/Live/im/api/en#Signature_Algorithm signature algorithm]}}
 +
{{api_args|extension|false|string|message extension field [http://open.weibo.com/wiki/Live/im/api/en#Data_Structure see] (json object format, the default is empty json object) }}
 +
{{api_args|offset|false|long|the time offset between sending message and the start of the live,unit:ms.If not pass, or pass the negative, do 0 process,indicating that the current message is not displayed when playing back.}}
 +
|}
 +
 
 +
 
 +
 
 +
'''Return result'''
 +
 
 +
//Successful return
 +
<pre class="brush:js">
 +
{
 +
    "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
 +
    "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:
+
//Failed to return
<pre>
+
<pre class="brush:js">
oauth_consumer_key - GDdmIQH6jhtmLUypg82gる
+
{
oauth_nonce - oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y
+
    "error_code": 91XX,
oauth_signature_method - HMAC-SHA1
+
    "error_msg": "xxxxxxxxx"
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>
  
Generate signature from the string that joined oauth_comsumer_secret and oauth_token_secret with &.
+
== Receive Comments-Pull Mode ==
key is:
+
'''Description'''
  
<pre>
+
This interface allows the third-party pull room messages from weibo live interactive system.After the third-party initiates the request,the interface will push the latest message in the room continuously as long as the connection is not broken.If the connection is disconnected accidentally,the message will continue to be pushed from the last disconnected position as long as the cumulative number of messages before the reconnection does not exceed the agreed threshold.
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]
 +
 
 +
 
 +
'''Support Formats'''
 +
 
 +
JSON
 +
 
 +
 
 +
'''Authorization'''
 +
 
 +
Required. More details of login authorization, Please refer to this WIKI [http://open.weibo.com/wiki/OAuth/en How to log in to authorization]
 +
 
 +
 
 +
'''Request parameter'''
 +
{| 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"|Parameter field
 +
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Requires
 +
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field Type
 +
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field description
 +
{{api_args| access_token|true|string|Required parameters when using OAuth authorization mode,obtained after OAuth authorization}}
 +
{{api_args|room_id|true|string|room id}}
 +
|}
 +
 
 +
'''Return Result'''
 +
 
 +
The return message is pushed in JSON mode, and the data structure is pushed as follows. Each message is a separate JSON-OBJECT.
 +
 
 +
//Successful return
 +
<pre class="brush:js">
 +
{
 +
    "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
 +
    "error_msg":"",
 +
}
 +
{
 +
    // message body. See Annex [Data structure / message body]
 +
}
 +
{
 +
    // message body.
 +
}
 +
...
 
</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"
+
//Failed to return
</pre>
+
<pre class="brush:js">
Response:
+
<pre>
+
 
{
 
{
weibo=null,
+
    "error_code": 91XX,
id=1803876591,
+
    "error_msg": "xxxxxxxxx"
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>
  
===Trips===
+
about error return values and error codes, see[http://open.weibo.com/wiki/Live/im/api/en#Error_code_definition  Error Code Definitions]
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”.
+
  
 +
== Receive Comments-Callback Mode ==
 +
'''Description'''
  
===Post weibo through OAuth===
+
If the third-party uses HTTP Callback mode to accept weibo messages,the third-party needs to provide an interface similar to [send message interface]. Requires the same parameters and return values as that interface.
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:
+
 
<pre>
+
'''URL'''
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
+
 
 +
customize by the third-party
 +
 
 +
 
 +
'''Support format'''
 +
 
 +
JSON
 +
 
 +
 
 +
'''HTTP request mode'''
 +
 
 +
POST
 +
 
 +
 
 +
'''Authorization'''
 +
 
 +
Required. More details of login authorization, Please refer to this WIKI[http://open.weibo.com/wiki/OAuth/en How to log in to authorization]
 +
 
 +
 
 +
'''Request parameter'''
 +
{| 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"|Parameter field
 +
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Requires
 +
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field Type
 +
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field description
 +
{{api_args| source |true|string|AppKey applied when applying for application,When calling an interface, it represents the unique identity of the application(This parameter is not required when using OAuth authorization mode)}}
 +
{{api_args|room_id|true|string|room id}}
 +
{{api_args|ts|true|long|Timestamp(The number of milliseconds from 1970-01-01 00:00:00)}}
 +
{{api_args|msg_type|true|int|Message Type 1 - Comment Message 2 - Praise message}}
 +
{{api_args|content|true|string|Message content}}
 +
{{api_args|uid|true|long|sender ID}}
 +
{{api_args|nickname|true|string|sender nickname}}
 +
{{api_args|avatar|true|string|sender avatar url}}
 +
{{api_args|sign|true|string|The result of signing all the parameters other than sign ,See[http://open.weibo.com/wiki/Live/im/api/en#Signature_Algorithm  signature algorithm]}}
 +
{{api_args|extension|false|string|message extension field[http://open.weibo.com/wiki/Live/im/api/en#Data_Structure see](json object format, the default is empty json object)}}
 +
{{api_args|offset|false|long|the time offset between sending message and the start of the live,unit:ms.If not pass, or pass the negative, do 0 process,indicating that the current message is not displayed when playing back.}}
 +
|}
 +
 
 +
 
 +
Return result
 +
 
 +
//Successful return
 +
<pre class="brush:js">
 +
{
 +
    "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
 +
    "error_msg":""
 +
}
 
</pre>
 
</pre>
Generate signature from the string that joined oauth_comsumer_secret and oauth_token_secret with &.
+
 
key is:
+
 
<pre>
+
//Failed to return
MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA
+
<pre class="brush:js">
</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>
+
 
{
 
{
     "created_at": "Mon Oct 11 12:00:16 +0800 2010",  
+
     "error_code": 91XX,
     "favorited": false,
+
     "error_msg": "xxxxxxxxx"
    "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==
+
== Signature Algorithm==
:ActionScript/Flash
+
'''Input:'''
::oauth-as3 http://code.google.com/p/oauth-as3/
+
::A flex oauth client  http://www.arcgis.com/home/item.html?id=ff6ffa302ad04a7194999f2ad08250d7
+
  
:C/C++
+
- the list of key-value pairs
::QTweetLib http://github.com/minimoog/QTweetLib
+
::libOAuth http://liboauth.sourceforge.net/
+
  
:clojure
+
- appsecret used to signature
::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
+
'''Output:'''
::erlang-oauth http://github.com/tim/erlang-oauth
+
  
:java
+
Signature Result String
::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
+
'''Algorithm:'''
::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
+
- Each of the key-value pair composes a string follows key=value format,each string is sorted by the dictionary order of the key(key is not the same),then a semiangle sign "&" is used to form a string.
::Net::OAuth http://oauth.googlecode.com/svn/code/perl/
+
  
:PHP
+
- The string is encoded in UTF-8 to get a byte sequence input,the secret string is encoded by UTF-8 to generate a byte sequence as the key,the byte sequence of the hash value is calculated in the form of hmac-md5,the hash-value byte sequence uses URL-safe-Base64 encoding,then take the 6th to 16th characters as the result output.
::tmhOAuth http://github.com/themattharris/tmhOAuth
+
 
::oauth-php http://code.google.com/p/oauth-php/
+
 
 +
'''Algorithm Example:'''
 +
 
 +
Assume that the input is:
 +
kv-pair: {"a":"1", "c":"jerry", "b":"tom"}
 +
appsecret:  123456
 +
 
 +
the concatenated string is:
 +
a=1&b=tom&c=jerry
 +
 
 +
hmac-md5("a=1&b=tom&c=jerry",123456)
 +
byte array output:[-117, -27, -78, -5, 73, 68, -64, -50, 4, 21, 16, -55, -55, -39, -31, -15]
 +
 
 +
converted to URL-safe base64 string:i-Wy-0lEwM4EFRDJydnh8Q==
 +
take the 6th to 16th characters(initial bit is 0), contains the 6th, does not contain the 16th, a total of 10 bits:lEwM4EFRDJ
 +
 
 +
 
 +
'''Signature results:'''
 +
 
 +
lEwM4EFRDJ
 +
 
 +
== Data Structure ==
 +
 
 +
'''Message Body'''
 +
<pre class="brush:js">
 +
{
 +
    "room_id":string,      // room id
 +
    "room_sys_id": uint64, // room id (internal)
 +
    "msg_type":int,        // Message type, see "Message Type Description"
 +
    "mid":long,
 +
    "sender_info":{
 +
        // user information of the sender, see "User Information"
 +
    },
 +
    "content":string,      // message content
 +
    "extension":string,    // The extended field of the message
 +
    "offset": long,        // the offset of message time from the video start time,unit:ms
 +
    "created_at":long  // Timestamp,the number of milliseconds from 1970-01-01 0:00:00 GMT
 +
      //If there are other fields, these fields continue here,related fields See "Additional fields for each message type"
 +
}
 +
 
 +
</pre>
 +
 
 +
'''extension'''
 +
 
 +
For the message types 1 to 14, each kind of message will have some unique fields used to represent the business, these fields will appear in the sys field inside of the extension, the structure is as follows:
 +
<pre class="brush:js">
 +
extension = {
 +
    "sys": {
 +
        // The fields that appear here are listed in "unique additional fields to each type".If the extra field list is empty, the "sys" field may not exist
 +
    },
 +
    // "Other transparent fields"
 +
}
 +
</pre>
 +
 
 +
unique additional fields to each type
 +
 
 +
<pre class="brush:js">
 +
chat message,msg_type=1
 +
"msg_behavior":uint32  //the display behavior of message  0: Default 1. Barrage
 +
 
 +
praise message,msg_type=2
 +
"praises_count":int    // Current total number of praise
 +
"inc_praises":long    // the number of times that users point like
 +
 
 +
banned,msg_type=4
 +
"shut_info":{          // the users be banned
 +
    "shutted_until":uint32  //the remaining time of the end of prohibition,unit:s
 +
    "members":[              //User list that be banned
 +
    {
 +
      "uid":uint64          //the UID of the user that be banned
 +
      "user_system":string  //the system that the banned user belongs to
 +
    }
 +
  ]
 +
}
 +
 
 +
room change,msg_type=11
 +
"live_status":int      // Indicates the status of the live broadcast
 +
"room_info": {
 +
    // Room information body, see "room information"
 +
}
 +
 
 +
join room and exit room,msg_type=12
 +
"exit_or_enter_room":int  // 0:exit 1:join
 +
"room_info": {
 +
    // Room information body, see "room information"
 +
}
 +
 
 +
add and delete administrator,msg_type=14
 +
"admin_info":{            // information of users that be added or deleted
 +
    "uid":uint64              //UID of the administrator
 +
    "user_system":string      //the system that the administrator belongs to
 +
    "type":int              //Operation Type 1:Add 2:Delete
 +
}
 +
</pre>
  
:Python
+
== Live Interface ==
::python-oauth2 http://github.com/brosner/python-oauth2
+
Please refer to[http://open.weibo.com/wiki/Live/api/en live interface documentation]
  
:Qt
+
== Message Type ==
::qOauth http://github.com/ayoy/qoauth
+
  
:Ruby
+
    1 - chat message
::Oauth ruby gem http://oauth.rubyforge.org/
+
    2 - praise message
 +
    3 - light the anchor message
 +
    4 - banned message
 +
    6 - announcement message
 +
    7 - share live messages
 +
    8 - focus on the anchor message
 +
    11 -live change message (any change in room status will be pushed)
 +
    12 - join / exit room message
 +
    13 - reward message
 +
    14 - administrator change message
 +
    100 - customize message type
  
:Scala
+
== Error code definition ==
::DataBinder Dispatch http://dispatch.databinder.net/About
+
<table class="wiki_table">
 +
<tr>
 +
<th style="width: 10%">error code</th>
 +
<th>error description</th>
 +
</tr>
 +
<tr>
 +
<td>9101</td>
 +
<td>authentication failed</td>
 +
</tr>
 +
<tr>
 +
<td>9102</td>
 +
<td>internal error</td>
 +
</tr>
 +
<tr>
 +
<td>9103</td>
 +
<td>data format error</td>
 +
</tr>
 +
<tr>
 +
<td>9104</td>
 +
<td>the message contains spam</td>
 +
</tr>
 +
<tr>
 +
<td>9105</td>
 +
<td>already exists</td>
 +
</tr>
 +
<tr>
 +
<td>9106</td>
 +
<td>data is not legal.the point that unlike 9103 : 9103 is the data format error, such as a int parameter should be passed but passed a string can not be resolved into int. And the current error code indicates that the data format itself is not a problem, but is an illegal data, such as ID corresponding entity does not exist.</td>
 +
</tr>
 +
<tr>
 +
<td>9107</td>
 +
<td>room is not allowed to speak</td>
 +
</tr>
 +
<tr>
 +
<td>9108</td>
 +
<td>user does not exist</td>
 +
</tr>
 +
<tr>
 +
<td>9109</td>
 +
<td>room does not exist</td>
 +
</tr>
 +
<tr>
 +
<td>9110</td>
 +
<td>token parse error</td>
 +
</tr>
 +
<tr>
 +
<td>9111</td>
 +
<td>room status is not correct</td>
 +
</tr>
 +
<tr>
 +
<td>9112</td>
 +
<td>the user is banned</td>
 +
</tr>
 +
<tr>
 +
<td>9113</td>
 +
<td>the current operation is not allowed</td>
 +
</tr>
 +
<tr>
 +
<td>1019</td>
 +
<td>the current operation is not supported</td>
 +
</tr>
 +
</table>

2017年2月24日 (五) 16:59的最后版本

目录

Overview

One of the cooperation mode between weibo and the third-party that access to weibo is server-side synchronization.This mode means doing message synchronization between live interactive system of weibo and interactive system of the third-party to implement message sharing. Send message interface and pull message interface(active pull and callback pull)can synchronize third-party messages to weibo.

Post Comments

Description

Post comment of the users to weibo live-im system.


URL

https://api.weibo.com/2/liveim/message/sync.json [POST]


Support Formats

JSON


Authorization

Required. More details of login authorization, Please refer to this WIKIHow to login to authorization


Request parameter

Parameter field Requires Field Type Field description
access_token true string Required parameters when using OAuth authorization mode,obtained after OAuth authorization
room_id true string room id
ts true long Timestamp(The number of milliseconds from 1970-01-01 00:00:00),cannot delay more than 2min
msg_type true int message types, see message types
content true string Message content
uid true long sender ID
nickname true string Sender nickname
avatar true string sender avatar url
sign true string The result of signing all the parameters other than sign ,See signature algorithm
extension false string message extension field see (json object format, the default is empty json object)
offset false long the time offset between sending message and the start of the live,unit:ms.If not pass, or pass the negative, do 0 process,indicating that the current message is not displayed when playing back.


Return result

//Successful return

{
    "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
    "error_msg":""
}


//Failed to return

{
    "error_code": 91XX,
    "error_msg": "xxxxxxxxx"
}

Receive Comments-Pull Mode

Description

This interface allows the third-party pull room messages from weibo live interactive system.After the third-party initiates the request,the interface will push the latest message in the room continuously as long as the connection is not broken.If the connection is disconnected accidentally,the message will continue to be pushed from the last disconnected position as long as the cumulative number of messages before the reconnection does not exceed the agreed threshold.


URL

https://api.weibo.com/2/liveim/message/pull.stream [GET]


Support Formats

JSON


Authorization

Required. More details of login authorization, Please refer to this WIKI How to log in to authorization


Request parameter

Parameter field Requires Field Type Field description
access_token true string Required parameters when using OAuth authorization mode,obtained after OAuth authorization
room_id true string room id

Return Result

The return message is pushed in JSON mode, and the data structure is pushed as follows. Each message is a separate JSON-OBJECT.

//Successful return

{
    "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
    "error_msg":"",
}
{
    // message body. See Annex [Data structure / message body]
}
{
    // message body.
}
...


//Failed to return

{
    "error_code": 91XX,
    "error_msg": "xxxxxxxxx"
}

about error return values and error codes, seeError Code Definitions

Receive Comments-Callback Mode

Description

If the third-party uses HTTP Callback mode to accept weibo messages,the third-party needs to provide an interface similar to [send message interface]. Requires the same parameters and return values as that interface.


URL

customize by the third-party


Support format

JSON


HTTP request mode

POST


Authorization

Required. More details of login authorization, Please refer to this WIKIHow to log in to authorization


Request parameter

Parameter field Requires Field Type Field description
source true string AppKey applied when applying for application,When calling an interface, it represents the unique identity of the application(This parameter is not required when using OAuth authorization mode)
room_id true string room id
ts true long Timestamp(The number of milliseconds from 1970-01-01 00:00:00)
msg_type true int Message Type 1 - Comment Message 2 - Praise message
content true string Message content
uid true long sender ID
nickname true string sender nickname
avatar true string sender avatar url
sign true string The result of signing all the parameters other than sign ,Seesignature algorithm
extension false string message extension fieldsee(json object format, the default is empty json object)
offset false long the time offset between sending message and the start of the live,unit:ms.If not pass, or pass the negative, do 0 process,indicating that the current message is not displayed when playing back.


Return result

//Successful return

{
    "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
    "error_msg":""
}


//Failed to return

{
    "error_code": 91XX,
    "error_msg": "xxxxxxxxx"
}

Signature Algorithm

Input:

- the list of key-value pairs

- appsecret used to signature


Output:

Signature Result String


Algorithm:

- Each of the key-value pair composes a string follows key=value format,each string is sorted by the dictionary order of the key(key is not the same),then a semiangle sign "&" is used to form a string.

- The string is encoded in UTF-8 to get a byte sequence input,the secret string is encoded by UTF-8 to generate a byte sequence as the key,the byte sequence of the hash value is calculated in the form of hmac-md5,the hash-value byte sequence uses URL-safe-Base64 encoding,then take the 6th to 16th characters as the result output.


Algorithm Example:

Assume that the input is:
kv-pair: {"a":"1", "c":"jerry", "b":"tom"}
appsecret:  123456
the concatenated string is:
a=1&b=tom&c=jerry
hmac-md5("a=1&b=tom&c=jerry",123456)
byte array output:[-117, -27, -78, -5, 73, 68, -64, -50, 4, 21, 16, -55, -55, -39, -31, -15]
converted to URL-safe base64 string:i-Wy-0lEwM4EFRDJydnh8Q==
take the 6th to 16th characters(initial bit is 0), contains the 6th, does not contain the 16th, a total of 10 bits:lEwM4EFRDJ


Signature results:

lEwM4EFRDJ

Data Structure

Message Body

{
    "room_id":string,      // room id
    "room_sys_id": uint64, // room id (internal)
    "msg_type":int,        // Message type, see "Message Type Description"
    "mid":long,
    "sender_info":{
        // user information of the sender, see "User Information"
    },
    "content":string,      // message content
    "extension":string,    // The extended field of the message
    "offset": long,        // the offset of message time from the video start time,unit:ms
    "created_at":long   // Timestamp,the number of milliseconds from 1970-01-01 0:00:00 GMT
      //If there are other fields, these fields continue here,related fields See "Additional fields for each message type"
}

extension

For the message types 1 to 14, each kind of message will have some unique fields used to represent the business, these fields will appear in the sys field inside of the extension, the structure is as follows:

extension = {
    "sys": {
        // The fields that appear here are listed in "unique additional fields to each type".If the extra field list is empty, the "sys" field may not exist 
    },
    // "Other transparent fields"
}

unique additional fields to each type

chat message,msg_type=1
"msg_behavior":uint32  //the display behavior of message  0: Default 1. Barrage
  
praise message,msg_type=2
"praises_count":int    // Current total number of praise
"inc_praises":long     // the number of times that users point like 
  
banned,msg_type=4
"shut_info":{          // the users be banned
    "shutted_until":uint32  //the remaining time of the end of prohibition,unit:s
    "members":[              //User list that be banned
     {
       "uid":uint64          //the UID of the user that be banned
       "user_system":string  //the system that the banned user belongs to 
     }
   ]
}
  
room change,msg_type=11
"live_status":int      // Indicates the status of the live broadcast
"room_info": {
    // Room information body, see "room information"
}
  
join room and exit room,msg_type=12
"exit_or_enter_room":int  // 0:exit 1:join
"room_info": {
    // Room information body, see "room information"
}
  
add and delete administrator,msg_type=14
"admin_info":{            // information of users that be added or deleted
    "uid":uint64              //UID of the administrator
    "user_system":string      //the system that the administrator belongs to 
    "type":int               //Operation Type 1:Add 2:Delete
}

Live Interface

Please refer tolive interface documentation

Message Type

   1 - chat message
   2 - praise message
   3 - light the anchor message
   4 - banned message
   6 - announcement message
   7 - share live messages
   8 - focus on the anchor message
   11 -live change message (any change in room status will be pushed)
   12 - join / exit room message
   13 - reward message
   14 - administrator change message
   100 - customize message type

Error code definition

error code error description
9101 authentication failed
9102 internal error
9103 data format error
9104 the message contains spam
9105 already exists
9106 data is not legal.the point that unlike 9103 : 9103 is the data format error, such as a int parameter should be passed but passed a string can not be resolved into int. And the current error code indicates that the data format itself is not a problem, but is an illegal data, such as ID corresponding entity does not exist.
9107 room is not allowed to speak
9108 user does not exist
9109 room does not exist
9110 token parse error
9111 room status is not correct
9112 the user is banned
9113 the current operation is not allowed
1019 the current operation is not supported
文档更新时间: 2017-02-24