2/messages/ask

跳转到: 导航, 搜索

粉丝给蓝V发送一对一消息接口

接口调用地址:https://m.api.weibo.com/2/messages/ask.json


HTTP请求方式:POST


是否需要登陆:是


频次限制:是


接口请求参数
参数名称 值的类型 是否必填 说明描述
access_token string true 采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。
uid int64 true 消息接收方蓝V用户ID。
type string true 需要以何种类型的消息类型发送。text:纯文本类型私信。
data string false 消息数据,具体内容严格遵循type类型对应格式。必须为json做URLEncode后的字符串格式,采用UTF-8编码。

注意事项

  • 1, 当前用户需要先完成Scope 授权,对应的scope权限参数为:direct_messages_write;
  • 2, 指定的uid用户为蓝V;
  • 3, 指定的uid蓝V用户已设置成将自己的微博私信、留言等消息箱服务交给当前应用托管;
  • 4, 指定的uid蓝V用户已开启推送服务(当前托管即自动开启);
  • 5, 当前登录用户必须为uid蓝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&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/ask.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"
        }
    ]
}
data参数支持的参数
参数名称 值的类型 是否必填 说明描述
articles:display_name string true 图文的显示名称标题
articles:summary string true 图文的文字描述
articles:image string false 图文的缩略显示图片
articles:url string true 图文的URL地址,点击后跳转

返回结果

// 成功返回
{
    "id": 1211260020031347,  //私信ID,非receive或reply接口中的消息ID
    "type": "text",
    "receiver_id": 1902538057,
    "sender_id": 2489518277,
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
    "text": "我的余额还剩多少?",
    "data": {}
}

// 失败返回
{
    "request": "/2/messages/ask.json",
    "error_code": "264XX",
    "error": "error message."
}
文档更新时间: 2013-10-11