2/messages/send
(未显示1个用户的12个中间版本) | |||
第1行: | 第1行: | ||
=消息发送接口= | =消息发送接口= | ||
功能: | 功能: | ||
− | + | 消息发送接口,认证用户给粉丝发送一对一私信接口 | |
第35行: | 第35行: | ||
|int64 | |int64 | ||
|true | |true | ||
− | | | + | |消息发送方的用户ID,该用户具有私信提醒的权限,详见:[[私信提醒|私信提醒指南文档]],已指定当前应用为其开发且已开启“开发模式”,详见:[[粉丝服务开发模式指南|粉丝服务开发模式指南]]。 |
|- | |- | ||
− | | | + | |receiver_id |
|int64 | |int64 | ||
|true | |true | ||
− | | | + | |消息接收方的用户ID,该用户必须为sender_id用户的粉丝 |
|- | |- | ||
|type | |type | ||
|string | |string | ||
|true | |true | ||
− | | | + | |需要以何种类型的消息类型发送。text:纯文本类型私信,articles:图文类型私信消息。 |
|- | |- | ||
|data | |data | ||
|string | |string | ||
− | | | + | |true |
|消息数据,具体内容严格遵循type类型对应格式。必须为json做URLEncode后的字符串格式,采用UTF-8编码。 | |消息数据,具体内容严格遵循type类型对应格式。必须为json做URLEncode后的字符串格式,采用UTF-8编码。 | ||
+ | |- | ||
+ | |annotations | ||
+ | |string | ||
+ | |false | ||
+ | |元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。每条微博可以包含一个或者多个元数据。必须为json做URLEncode后的字符串格式,字串长度不超过512个字符,具体内容可以自定。例:annotations='[{"type2":123}, {"a":"b", "c":"d"}]'; 。 | ||
|} | |} | ||
− | 注意事项 | + | ==注意事项== |
*1、为确保应用及V用户信息安全,此接口必须在服务器端调用; | *1、为确保应用及V用户信息安全,此接口必须在服务器端调用; | ||
− | * | + | *2、调用接口的登录用户必须为当前应用的所有者,通过Base Auth的方式调用,详见type为text时的举例; |
− | * | + | *未明确告知用户关注后将获得哪些服务提醒的认证用户,从而导致用户投诉将无限期关停接口。 |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==当前支持发送的消息类型(type)中,data支持的参数== | ==当前支持发送的消息类型(type)中,data支持的参数== | ||
− | + | <h3>1、纯文本类型私信消息:text</h3> | |
<pre> | <pre> | ||
{ | { | ||
第93行: | 第92行: | ||
则对应的调用为: | 则对应的调用为: | ||
<pre> | <pre> | ||
− | curl -u "USERNAME:PASSWORD" -d "source=YOUR_APPKEY&sender_id=******& | + | curl -u "USERNAME:PASSWORD" -d "source=YOUR_APPKEY&sender_id=******&receiver_id=******&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/send.json" -k |
</pre> | </pre> | ||
− | + | <h3>2、图文类型私信消息:articles</h3> | |
<pre> | <pre> | ||
{ | { | ||
第120行: | 第119行: | ||
|style="text-align:center;width: 11%"|是否必填 | |style="text-align:center;width: 11%"|是否必填 | ||
|style="text-align:center;"|说明描述 | |style="text-align:center;"|说明描述 | ||
+ | |- | ||
+ | |articles | ||
+ | |string | ||
+ | |true | ||
+ | |图文数组,最多支持8个图文,建议为1或3个 | ||
|- | |- | ||
|articles:display_name | |articles:display_name | ||
第129行: | 第133行: | ||
|string | |string | ||
|true | |true | ||
− | | | + | |图文的文字描述,大于等于2个图文时,仅显示第一个图文的描述 |
|- | |- | ||
|articles:image | |articles:image | ||
第142行: | 第146行: | ||
|} | |} | ||
+ | |||
+ | <h3>3、位置类型私信消息:position </h3> | ||
+ | <pre> | ||
+ | { | ||
+ | "longitude": "116.308586", | ||
+ | "latitude": "39.982525" | ||
+ | } | ||
+ | </pre> | ||
+ | <div class="wiki_kit"> | ||
+ | {|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table" | ||
+ | <html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html> | ||
+ | !colspan="4" scope="col" |<span id="data参数支持的参数">data参数支持的参数</span> | ||
+ | |- | ||
+ | |style="text-align:center; width: 12%"|参数名称 | ||
+ | |style="text-align:center;width: 12%"|值的类型 | ||
+ | |style="text-align:center;width: 11%"|是否必填 | ||
+ | |style="text-align:center;"|说明描述 | ||
+ | |- | ||
+ | |longitude | ||
+ | |string | ||
+ | |true | ||
+ | |经度 | ||
+ | |- | ||
+ | |latitude | ||
+ | |string | ||
+ | |true | ||
+ | |纬度 | ||
+ | |} | ||
==返回结果== | ==返回结果== | ||
<pre> | <pre> | ||
第147行: | 第179行: | ||
{ | { | ||
"id": 1211260020031347, | "id": 1211260020031347, | ||
− | "type": "TYPE", | + | "type": "TYPE", |
− | " | + | "receiver_id": 1902538057, |
"sender_id": 2489518277, | "sender_id": 2489518277, | ||
"created_at": "Mon Jul 16 18:09:20 +0800 2012", | "created_at": "Mon Jul 16 18:09:20 +0800 2012", | ||
第158行: | 第190行: | ||
{ | { | ||
"request": "/2/messages/send.json", | "request": "/2/messages/send.json", | ||
− | "error_code": | + | "error_code": 264XX, |
"error": "error message." | "error": "error message." | ||
} | } |
2014年2月18日 (二) 17:14的最后版本
消息发送接口
功能: 消息发送接口,认证用户给粉丝发送一对一私信接口
接口调用地址:https://m.api.weibo.com/2/messages/send.json
HTTP请求方式:POST
是否需要登陆:是
频次限制:是
接口请求参数 | |||
---|---|---|---|
参数名称 | 值的类型 | 是否必填 | 说明描述 |
source | string | true | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。 |
sender_id | int64 | true | 消息发送方的用户ID,该用户具有私信提醒的权限,详见:私信提醒指南文档,已指定当前应用为其开发且已开启“开发模式”,详见:粉丝服务开发模式指南。 |
receiver_id | int64 | true | 消息接收方的用户ID,该用户必须为sender_id用户的粉丝 |
type | string | true | 需要以何种类型的消息类型发送。text:纯文本类型私信,articles:图文类型私信消息。 |
data | string | true | 消息数据,具体内容严格遵循type类型对应格式。必须为json做URLEncode后的字符串格式,采用UTF-8编码。 |
annotations | string | false | 元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。每条微博可以包含一个或者多个元数据。必须为json做URLEncode后的字符串格式,字串长度不超过512个字符,具体内容可以自定。例:annotations='[{"type2":123}, {"a":"b", "c":"d"}]'; 。 |
注意事项
- 1、为确保应用及V用户信息安全,此接口必须在服务器端调用;
- 2、调用接口的登录用户必须为当前应用的所有者,通过Base Auth的方式调用,详见type为text时的举例;
- 未明确告知用户关注后将获得哪些服务提醒的认证用户,从而导致用户投诉将无限期关停接口。
当前支持发送的消息类型(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&sender_id=******&receiver_id=******&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/send.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 | string | true | 图文数组,最多支持8个图文,建议为1或3个 |
articles:display_name | string | true | 图文的显示名称标题 |
articles:summary | string | true | 图文的文字描述,大于等于2个图文时,仅显示第一个图文的描述 |
articles:image | string | false | 图文的缩略显示图片 |
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/send.json", "error_code": 264XX, "error": "error message." }
文档更新时间: 2014-02-18