Direct messages/sent
目录 |
direct_messages/sent
返回登录用户已发送的最新n条私信,每条私信包含发送者和接受者的详细信息。
URL
http://api.t.sina.com.cn/direct_messages/sent.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
GET
是否需要登录
true
关于授权机制,参见授权机制声明
请求数限制
true
关于请求数限制,参见接口访问权限说明
请求参数
必选 | 类型及范围 | 说明 | |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数) |
since_id | false | int64 | 若指定此参数,则只返回ID比since_id大的记录(比since_id发送时间晚)。 |
max_id | false | int64 | 若指定此参数,则返回ID小于或等于max_id的记录 |
count | false | int,默认值20,最大值200。 | 单页返回的记录条数。 |
page | false | int,默认值1。 | 返回结果的页码。 |
注意事项
无
返回结果
XML示例
<?xml version="1.0" encoding="UTF-8"?> <direct-messages> <direct_message> <created_at>Sun Nov 28 00:27:57 +0800 2010</created_at> <id>686758059</id> <text>必须的。哈哈。</text> <sender_id>1658122963</sender_id> <recipient_id>1874874647</recipient_id> <sender_screen_name>zhangwei217245</sender_screen_name> <recipient_screen_name>Bybeye</recipient_screen_name> <sender> <id>1658122963</id> <screen_name>zhangwei217245</screen_name> <name>zhangwei217245</name> <province>11</province> <city>5</city> <location>北京 朝阳区</location> <description>ABCDE</description> <url/> <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url> <domain>zhangwei217245</domain> <gender>m</gender> <followers_count>24</followers_count> <friends_count>44</friends_count> <statuses_count>118</statuses_count> <favourites_count>3</favourites_count> <created_at>Tue Nov 03 00:00:00 +0800 2009</created_at> <following>false</following> <verified>false</verified> <allow_all_act_msg>false</allow_all_act_msg> <geo_enabled>true</geo_enabled> </sender> <recipient> <id>1874874647</id> <screen_name>Bybeye</screen_name> <name>Bybeye</name> <province>11</province> <city>1000</city> <location>北京</location> <description>No windows</description> <url>http://1</url> <profile_image_url>http://tp4.sinaimg.cn/1874874647/50/0/1</profile_image_url> <domain>bybeye</domain> <gender>m</gender> <followers_count>7</followers_count> <friends_count>22</friends_count> <statuses_count>18</statuses_count> <favourites_count>8</favourites_count> <created_at>Thu Nov 25 00:00:00 +0800 2010</created_at> <following>false</following> <verified>false</verified> <allow_all_act_msg>false</allow_all_act_msg> <geo_enabled>false</geo_enabled> </recipient> </direct_message> ... </direct-messages>
JSON示例
[ { "sender_screen_name" : "zhangwei217245", "recipient_screen_name" : "Bybeye", "text" : "必须的。哈哈。", "recipient" : { "name" : "Bybeye", "domain" : "bybeye", "geo_enabled" : false, "followers_count" : 7, "statuses_count" : 18, "favourites_count" : 8, "city" : "1000", "description" : "No windows", "verified" : false, "id" : 1874874647, "gender" : "m", "friends_count" : 22, "screen_name" : "Bybeye", "allow_all_act_msg" : false, "following" : false, "url" : "http://1", "profile_image_url" : "http://tp4.sinaimg.cn/1874874647/50/0/1", "created_at" : "Thu Nov 25 00:00:00 +0800 2010", "province" : "11", "location" : "北京" }, "sender" : { "name" : "zhangwei217245", "domain" : "zhangwei217245", "geo_enabled" : true, "followers_count" : 24, "statuses_count" : 118, "favourites_count" : 3, "city" : "5", "description" : "ABCDE", "verified" : false, "id" : 1658122963, "gender" : "m", "friends_count" : 44, "screen_name" : "zhangwei217245", "allow_all_act_msg" : false, "following" : false, "url" : "", "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213", "created_at" : "Tue Nov 03 00:00:00 +0800 2009", "province" : "11", "location" : "北京 朝阳区" }, "sender_id" : 1658122963, "recipient_id" : 1874874647, "id" : 686758059, "created_at" : "Sun Nov 28 00:27:57 +0800 2010" }, ... ]
字段说明 - direct_message
- id: 私信ID
- text: 私信内容
- sender_id:发送人UID
- recipient_id: 接受人UID
- created_at: 发送时间
- sender_screen_name: 发送人昵称
- recipient_screen_name:接受人昵称
- sender: 发送人信息,参考user说明
- recipient: 接受人信息,参考user说明
字段说明 - user
- id: 用户UID
- screen_name: 微博昵称
- name: 友好显示名称,同微博昵称
- province: 省份编码(参考省份编码表)
- city: 城市编码(参考城市编码表)
- location:地址
- description: 个人描述
- url: 用户博客地址
- profile_image_url: 自定义图像
- domain: 用户个性化URL
- gender: 性别,m--男,f--女,n--未知
- followers_count: 粉丝数
- friends_count: 关注数
- statuses_count: 微博数
- favourites_count: 收藏数
- created_at: 创建时间
- following: 是否已关注(此特性暂不支持)
- verified: 加V标示,是否微博认证用户
其他
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示例如下:
package weibo4j.examples; import weibo4j.DirectMessage; import weibo4j.Weibo; import weibo4j.WeiboException; import java.util.List; public class GetSentDirectMessages { /** * Usage: java Weibo4j.examples.GetDirectMessages ID Password * @param args String[] */ public static void main(String[] args) { if (args.length < 2) { System.out.println("No WeiboID/Password specified."); System.out.println( "Usage: java weibo4j.examples.GetDirectMessages ID Password"); System.exit( -1); } Weibo weibo = new Weibo(args[0], args[1]); try { List<DirectMessage> messages = weibo.getSentDirectMessages(); for (DirectMessage message : messages) { System.out.println("Sender:" + message.getSenderScreenName()); System.out.println("Text:" + message.getText() + "\n"); } System.exit(0); } catch (WeiboException te) { System.out.println("Failed to get messages: " + te.getMessage()); System.exit( -1); } } }
PHP示例
请从 微博SDK开发包下载 处下载PHP SDK(支持OAuth验证之版本)
代码示例如下:
//Direct messages/sent $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); $msg = $c->list_dm_sent(); if ($msg === false || $msg === null){ echo "Error occured"; return false; } if (isset($msg['error_code']) && isset($msg['error'])){ echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] ); return false; } foreach($msg as $mail){ echo('Sender: '.$mail['sender_screen_name'].' Text: '.$mail['text'].' ; '); }