2/messages/reply
(→接口请求参数) |
|||
(未显示3个用户的21个中间版本) | |||
第1行: | 第1行: | ||
=消息回复接口= | =消息回复接口= | ||
− | + | ||
消息回复接口,对接收到的指定新消息进行回复 | 消息回复接口,对接收到的指定新消息进行回复 | ||
+ | ==URL== | ||
+ | https://m.api.weibo.com/2/messages/reply.json | ||
− | + | ==HTTP请求方式== | |
+ | POST | ||
+ | ==是否需要登录== | ||
+ | 是<br/> | ||
+ | 关于登录授权,参见 [[授权机制说明|如何登录授权]] | ||
− | |||
− | + | ==接口请求参数== | |
− | + | {| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color: #CCCCCC;" | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | {| | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | !width="10%" style="text-align:center;font-weight:bolder;border:1px solid #cccccc"| | |
− | + | !width="5%" style="text-align:center;font-weight:bolder;border:1px solid #cccccc"|必选 | |
− | + | !width="10%" style="text-align:center;font-weight:bolder;border:1px solid #cccccc"|类型及范围 | |
− | + | !width="75%" style="text-align:center;font-weight:bolder;border:1px solid #cccccc"|说明 | |
− | + | {{api_args|source|false|string|采用OAuth授权方式不需要此参数,其他授权方式为必填参数,数值为应用的AppKey。}} | |
− | |source | + | {{api_args|access_token|false|string|采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。}} |
− | |string | + | {{api_args|type|true|string|需要以何种类型的消息进行响应,text:纯文本、articles:图文、position:位置。}} |
− | | | + | {{api_args|data|true|string|消息数据,具体内容严格遵循type类型对应格式,必须为json做URLEncode后的字符串格式,采用UTF-8编码。}} |
− | | | + | {{api_args|receiver_id|false|int64|消息接收方的ID。}} |
− | | | + | {{api_args|id|false|int64|需要响应的消息ID,该字段仅仅针对使用message/receive长连接服务接收到的消息;如果使用消息推送服务,则必须使用receiver_id参数而不是id参数}} |
− | | | + | {{api_args|save_sender_box|false|int|取值为0或1,不填则默认为1。取值为0时,通过message/reply发送的消息不会进入发送方的私信箱,取值为1时,通过message/reply发送的消息会进入发送方的私信箱。}} |
− | | | + | |
− | |true | + | |
− | | | + | |
− | | | + | |
− | | | + | |
− | + | ||
− | |true | + | |
− | | | + | |
− | |- | + | |
− | | | + | |
− | | | + | |
− | | | + | |
− | | | + | |
|} | |} | ||
==注意事项== | ==注意事项== | ||
− | * | + | *1、接口调用支持两种方式,一是采用OAuth方式调用,二是使用appkey所有者帐号通过Base Auth的方式调用; |
− | * | + | *2、如果调用走OAuth方式,则access_token参数必填,id参数和receiver_id参数必填一个; |
− | * | + | *3、如果调用走Base Auth方式,则调用接口的登录帐号必须为当前应用的所有者,并且source参数必填,id参数必填; |
− | * | + | *4、使用message/receive长连接服务接收上行信息的开发者才能获取到消息id参数,使用消息推送服务的开发者无法获取消息id参数,因此需要通过receiver_id来指定消息接收方,而消息发送方的uid微博会从access_token中获取; |
− | * | + | *5、调用接口时,需要消息发送方有针对于消息接收方的消息配额;一般来说,如果消息接收方给消息发送方主动发送过消息,则在7天内,消息发送方具备针对于消息接收方的主动配额一条; |
− | * | + | *6、调用时如果指定了id参数,则需要 |
− | + | ** 指定ID的新消息对应的原接收者已指定当前应用为其开发,且该接收者已开启“开发模式”,详见:[[粉丝服务开发模式指南|粉丝服务开发模式指南]]; | |
− | * | + | ** 指定ID的新消息对应的原接收者身份发出此消息; |
− | * | + | ** 指定ID的新消息对应的原发送者将收到此消息; |
+ | ** 发送者未被屏蔽或拉黑时消息进私信箱; | ||
此接口不得用于推广或引导用户使用任何与新浪微博有直接竞争关系的公司的服务,否则将永久关停指定应用或V用户使用资格。 | 此接口不得用于推广或引导用户使用任何与新浪微博有直接竞争关系的公司的服务,否则将永久关停指定应用或V用户使用资格。 | ||
+ | |||
+ | ==PHP示例代码== | ||
+ | |||
+ | PHP示例代码下载:[[Messages/dev_demo|下载]] | ||
==蓝V可回复的私信类型== | ==蓝V可回复的私信类型== | ||
+ | |||
当前支持蓝V回复的私信类型(type)中,data参数支持的参数: | 当前支持蓝V回复的私信类型(type)中,data参数支持的参数: | ||
+ | |||
+ | |||
<h3>1、纯文本类型私信消息:text</h3> | <h3>1、纯文本类型私信消息:text</h3> | ||
<pre> | <pre> | ||
第68行: | 第61行: | ||
</pre> | </pre> | ||
<div class="wiki_kit"> | <div class="wiki_kit"> | ||
+ | |||
+ | |||
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | {|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | ||
<html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html> | <html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html> | ||
第105行: | 第100行: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | |||
<div class="wiki_kit"> | <div class="wiki_kit"> | ||
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | {|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | ||
第123行: | 第120行: | ||
|string | |string | ||
|true | |true | ||
− | | | + | |图文的文字描述,大于等于2个图文时,仅显示第一个图文的描述 |
|- | |- | ||
|articles:image | |articles:image | ||
第144行: | 第141行: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | |||
<div class="wiki_kit"> | <div class="wiki_kit"> | ||
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | {|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | ||
第182行: | 第181行: | ||
{ | { | ||
"request": "/2/messages/reply.json", | "request": "/2/messages/reply.json", | ||
− | "error_code": | + | "error_code": 264XX, |
"error": "error message." | "error": "error message." | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | |||
__NOTOC__ | __NOTOC__ |
2014年6月3日 (二) 11:55的最后版本
消息回复接口
消息回复接口,对接收到的指定新消息进行回复
URL
https://m.api.weibo.com/2/messages/reply.json
HTTP请求方式
POST
是否需要登录
是
关于登录授权,参见 如何登录授权
接口请求参数
必选 | 类型及范围 | 说明 | |
---|---|---|---|
source | false | string | 采用OAuth授权方式不需要此参数,其他授权方式为必填参数,数值为应用的AppKey。 |
access_token | false | string | 采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。 |
type | true | string | 需要以何种类型的消息进行响应,text:纯文本、articles:图文、position:位置。 |
data | true | string | 消息数据,具体内容严格遵循type类型对应格式,必须为json做URLEncode后的字符串格式,采用UTF-8编码。 |
receiver_id | false | int64 | 消息接收方的ID。 |
id | false | int64 | 需要响应的消息ID,该字段仅仅针对使用message/receive长连接服务接收到的消息;如果使用消息推送服务,则必须使用receiver_id参数而不是id参数 |
save_sender_box | false | int | 取值为0或1,不填则默认为1。取值为0时,通过message/reply发送的消息不会进入发送方的私信箱,取值为1时,通过message/reply发送的消息会进入发送方的私信箱。 |
注意事项
- 1、接口调用支持两种方式,一是采用OAuth方式调用,二是使用appkey所有者帐号通过Base Auth的方式调用;
- 2、如果调用走OAuth方式,则access_token参数必填,id参数和receiver_id参数必填一个;
- 3、如果调用走Base Auth方式,则调用接口的登录帐号必须为当前应用的所有者,并且source参数必填,id参数必填;
- 4、使用message/receive长连接服务接收上行信息的开发者才能获取到消息id参数,使用消息推送服务的开发者无法获取消息id参数,因此需要通过receiver_id来指定消息接收方,而消息发送方的uid微博会从access_token中获取;
- 5、调用接口时,需要消息发送方有针对于消息接收方的消息配额;一般来说,如果消息接收方给消息发送方主动发送过消息,则在7天内,消息发送方具备针对于消息接收方的主动配额一条;
- 6、调用时如果指定了id参数,则需要
- 指定ID的新消息对应的原接收者已指定当前应用为其开发,且该接收者已开启“开发模式”,详见:粉丝服务开发模式指南;
- 指定ID的新消息对应的原接收者身份发出此消息;
- 指定ID的新消息对应的原发送者将收到此消息;
- 发送者未被屏蔽或拉黑时消息进私信箱;
此接口不得用于推广或引导用户使用任何与新浪微博有直接竞争关系的公司的服务,否则将永久关停指定应用或V用户使用资格。
PHP示例代码
PHP示例代码下载:下载
蓝V可回复的私信类型
当前支持蓝V回复的私信类型(type)中,data参数支持的参数:
1、纯文本类型私信消息:text
{ "text": "纯文本回复" }
data参数支持的参数 | |||
---|---|---|---|
参数名称 | 值的类型 | 是否必填 | 说明描述 |
text | string | true | 要回复的私信文本内容。文本大小必须小于300个汉字。 |
举例: 当data对应json为{"text": "纯文本响应"} 时,则进行URLEncode后对应data参数值为:"%7b%0a++++%22text%22%3a+%22%e7%ba%af%e6%96%87%e6%9c%ac%e5%93%8d%e5%ba%94%22%0a%7d"。
则对应的调用为:
curl -u "USERNAME:PASSWORD" -d "source=YOUR_APPKEY&id=1307180000*****&type=text&data=%7b%0a++++%22text%22%3a+%22%e7%ba%af%e6%96%87%e6%9c%ac%e5%93%8d%e5%ba%94%22%0a%7d" "https://m.api.weibo.com/2/messages/reply.json" -k
2、图文类型私信消息:articles
{ "articles": [ { "display_name": "两个故事", "summary": "今天讲两个故事,分享给你。谁是公司?谁又是中国人?", "image": "http://storage.mcp.weibo.cn/0JlIv.jpg", "url": "http://e.weibo.com/mediaprofile/article/detail?uid=1722052204&aid=983319" }, ... //最多支持8个图文,建议为1或3个 ] }
data参数支持的参数 | |||
---|---|---|---|
参数名称 | 值的类型 | 是否必填 | 说明描述 |
articles:display_name | string | true | 图文的显示名称标题 |
articles:summary | string | true | 图文的文字描述,大于等于2个图文时,仅显示第一个图文的描述 |
articles:image | string | true | 图文的缩略显示图片,需为JPG、PNG格式,单图及多图第一张推荐使用280*155,多图非第一张推荐使用64*64 |
articles:url | string | true | 图文的URL地址,点击后跳转 |
3、位置类型私信消息:position
{ "longitude": "116.308586", "latitude": "39.982525" }
data参数支持的参数 | |||
---|---|---|---|
参数名称 | 值的类型 | 是否必填 | 说明描述 |
longitude | string | true | 经度 |
latitude | string | true | 纬度 |
返回结果
// 成功返回 { "id": 1211260020031347, "type": "TYPE", "receiver_id": 1902538057, "sender_id": 2489518277, "created_at": "Mon Jul 16 18:09:20 +0800 2012", "text": "您的余额还剩2元。", "data": {} } // 失败返回 { "request": "/2/messages/reply.json", "error_code": 264XX, "error": "error message." }
文档更新时间: 2014-06-03