Direct messages/sent
(→返回结果) |
|||
第29行: | 第29行: | ||
===返回结果=== | ===返回结果=== | ||
− | + | ====XML==== | |
− | + | <pre> | |
− | + | <?xml version="1.0" encoding="UTF-8"?> | |
− | + | <direct-messages> | |
<direct_message> | <direct_message> | ||
− | <created_at> | + | <created_at>Mon Sep 13 18:01:26 +0800 2010</created_at> |
− | <id> | + | <id>395766358</id> |
− | <text> | + | <text>测试发个私信</text> |
− | <sender_id> | + | <sender_id>1642466141</sender_id> |
− | <recipient_id> | + | <recipient_id>1790486583</recipient_id> |
− | <sender_screen_name> | + | <sender_screen_name>huchao</sender_screen_name> |
− | <recipient_screen_name> | + | <recipient_screen_name>zoe乔</recipient_screen_name> |
<sender> | <sender> | ||
− | <id> | + | <id>1642466141</id> |
− | <screen_name> | + | <screen_name>huchao</screen_name> |
− | <name> | + | <name>huchao</name> |
− | <province> | + | <province>11</province> |
− | <city> | + | <city>8</city> |
− | <location></location> | + | <location>北京 海淀区</location> |
− | <description></description> | + | <description>Blogger,苹果迷,Google粉。</description> |
− | <url></url> | + | <url>http://tuoniao.org</url> |
− | <profile_image_url>http:// | + | <profile_image_url>http://tp2.sinaimg.cn/1642466141/50/1281523744</profile_image_url> |
− | <domain> | + | <domain>westy</domain> |
− | <gender></gender> | + | <gender>m</gender> |
− | <followers_count> | + | <followers_count>65</followers_count> |
− | <friends_count> | + | <friends_count>59</friends_count> |
− | <statuses_count> | + | <statuses_count>137</statuses_count> |
− | <favourites_count> | + | <favourites_count>1</favourites_count> |
− | <created_at> | + | <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at> |
<following>false</following> | <following>false</following> | ||
<verified>false</verified> | <verified>false</verified> | ||
+ | <allow_all_act_msg>false</allow_all_act_msg> | ||
<geo_enabled>false</geo_enabled> | <geo_enabled>false</geo_enabled> | ||
</sender> | </sender> | ||
<recipient> | <recipient> | ||
− | <id> | + | <id>1790486583</id> |
− | <screen_name> | + | <screen_name>zoe乔</screen_name> |
− | <name> | + | <name>zoe乔</name> |
− | <province> | + | <province>11</province> |
− | <city> | + | <city>8</city> |
− | <location></location> | + | <location>北京 海淀区</location> |
− | <description | + | <description/> |
− | <url | + | <url/> |
− | <profile_image_url>http://tp4.sinaimg.cn/ | + | <profile_image_url>http://tp4.sinaimg.cn/1790486583/50/1281325895</profile_image_url> |
− | <domain> | + | <domain>yymyzm</domain> |
− | <gender></gender> | + | <gender>f</gender> |
− | <followers_count> | + | <followers_count>5</followers_count> |
− | <friends_count> | + | <friends_count>4</friends_count> |
− | <statuses_count> | + | <statuses_count>7</statuses_count> |
− | <favourites_count> | + | <favourites_count>0</favourites_count> |
− | <created_at> | + | <created_at>Mon Aug 09 00:00:00 +0800 2010</created_at> |
<following>false</following> | <following>false</following> | ||
− | <verified> | + | <verified>false</verified> |
+ | <allow_all_act_msg>false</allow_all_act_msg> | ||
<geo_enabled>false</geo_enabled> | <geo_enabled>false</geo_enabled> | ||
</recipient> | </recipient> | ||
</direct_message> | </direct_message> | ||
− | + | </direct-messages> | |
− | + | </pre> | |
− | + | ====JSON==== | |
− | + | <pre> | |
− | + | [ | |
− | {"created_at":" | + | { |
− | + | "id":395766358, | |
− | + | "created_at":"Mon Sep 13 18:01:26 +0800 2010", | |
− | + | "text":"测试发个私信", | |
− | + | "sender_id":1642466141, | |
− | + | "recipient_id":1790486583, | |
− | + | "sender_screen_name":"huchao", | |
− | + | "recipient_screen_name":"zoe乔", | |
− | + | "sender":{ | |
− | + | "id":1642466141, | |
− | + | "screen_name":"huchao", | |
− | + | "name":"huchao", | |
− | + | "province":"11", | |
− | + | "city":"8", | |
− | + | "location":"北京 海淀区", | |
− | + | "description":"Blogger,苹果迷,Google粉。", | |
− | + | "url":"http://tuoniao.org", | |
− | + | "profile_image_url":"http://tp2.sinaimg.cn/1642466141/50/1281523744", | |
− | + | "domain":"westy", | |
− | + | "gender":"m", | |
− | + | "followers_count":65, | |
− | + | "friends_count":59, | |
− | + | "statuses_count":137, | |
− | + | "favourites_count":1, | |
− | + | "created_at":"Fri Aug 28 00:00:00 +0800 2009", | |
− | + | "following":false, | |
− | + | "allow_all_act_msg":false, | |
− | + | "geo_enabled":false, | |
− | + | "verified":false | |
− | + | }, | |
− | + | "recipient":{ | |
− | + | "id":1790486583, | |
− | + | "screen_name":"zoe乔", | |
− | + | "name":"zoe乔", | |
− | + | "province":"11", | |
− | + | "city":"8", | |
− | + | "location":"北京 海淀区", | |
− | + | "description":"", | |
− | + | "url":"", | |
− | + | "profile_image_url":"http://tp4.sinaimg.cn/1790486583/50/1281325895", | |
− | + | "domain":"yymyzm", | |
− | + | "gender":"f", | |
− | + | "followers_count":5, | |
− | + | "friends_count":4, | |
− | + | "statuses_count":7, | |
− | + | "favourites_count":0, | |
− | + | "created_at":"Mon Aug 09 00:00:00 +0800 2010", | |
− | + | "following":false, | |
− | + | "allow_all_act_msg":false, | |
+ | "geo_enabled":false, | ||
+ | "verified":false | ||
+ | } | ||
+ | } | ||
+ | ] | ||
+ | </pre> | ||
{{param_DM}} | {{param_DM}} | ||
{{param_user}} | {{param_user}} | ||
+ | |||
===使用示例=== | ===使用示例=== | ||
2010年9月13日 (一) 18:03的版本
目录 |
发送私信
返回登录用户已发送最新20条私信。XML和JSON的版本有包括发送者和接受者的详细资料。
URL
http://api.t.sina.com.cn/direct_messages/sent.format
格式
xml, json, rss, atom
HTTP请求方式
GET
是否需要身份验证
true
请求数限制
true
请求参数
- since_id. 可选参数. 返回ID比数值since_id大(比since_id时间晚的)的私信。
o 示例: http://api.t.sina.com.cn/direct_messages/sent.xml?since_id=12345
- max_id. 可选参数. 返回ID不大于max_id(时间不晚于max_id)的私信。
o 示例: http://api.t.sina.com.cn/direct_messages/sent.xml?max_id=54321
- count. 可选参数. 每次返回的最大记录数(即页面大小),不大于200。
o 示例: http://api.t.sina.com.cn/direct_messages/sent.xml?count=5
- page. 可选参数. 返回结果的页序号。注意:有分页限制。
o 示例: http://api.t.sina.com.cn/direct_messages/sent.xml?page=3
返回结果
XML
<?xml version="1.0" encoding="UTF-8"?> <direct-messages> <direct_message> <created_at>Mon Sep 13 18:01:26 +0800 2010</created_at> <id>395766358</id> <text>测试发个私信</text> <sender_id>1642466141</sender_id> <recipient_id>1790486583</recipient_id> <sender_screen_name>huchao</sender_screen_name> <recipient_screen_name>zoe乔</recipient_screen_name> <sender> <id>1642466141</id> <screen_name>huchao</screen_name> <name>huchao</name> <province>11</province> <city>8</city> <location>北京 海淀区</location> <description>Blogger,苹果迷,Google粉。</description> <url>http://tuoniao.org</url> <profile_image_url>http://tp2.sinaimg.cn/1642466141/50/1281523744</profile_image_url> <domain>westy</domain> <gender>m</gender> <followers_count>65</followers_count> <friends_count>59</friends_count> <statuses_count>137</statuses_count> <favourites_count>1</favourites_count> <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at> <following>false</following> <verified>false</verified> <allow_all_act_msg>false</allow_all_act_msg> <geo_enabled>false</geo_enabled> </sender> <recipient> <id>1790486583</id> <screen_name>zoe乔</screen_name> <name>zoe乔</name> <province>11</province> <city>8</city> <location>北京 海淀区</location> <description/> <url/> <profile_image_url>http://tp4.sinaimg.cn/1790486583/50/1281325895</profile_image_url> <domain>yymyzm</domain> <gender>f</gender> <followers_count>5</followers_count> <friends_count>4</friends_count> <statuses_count>7</statuses_count> <favourites_count>0</favourites_count> <created_at>Mon Aug 09 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
[ { "id":395766358, "created_at":"Mon Sep 13 18:01:26 +0800 2010", "text":"测试发个私信", "sender_id":1642466141, "recipient_id":1790486583, "sender_screen_name":"huchao", "recipient_screen_name":"zoe乔", "sender":{ "id":1642466141, "screen_name":"huchao", "name":"huchao", "province":"11", "city":"8", "location":"北京 海淀区", "description":"Blogger,苹果迷,Google粉。", "url":"http://tuoniao.org", "profile_image_url":"http://tp2.sinaimg.cn/1642466141/50/1281523744", "domain":"westy", "gender":"m", "followers_count":65, "friends_count":59, "statuses_count":137, "favourites_count":1, "created_at":"Fri Aug 28 00:00:00 +0800 2009", "following":false, "allow_all_act_msg":false, "geo_enabled":false, "verified":false }, "recipient":{ "id":1790486583, "screen_name":"zoe乔", "name":"zoe乔", "province":"11", "city":"8", "location":"北京 海淀区", "description":"", "url":"", "profile_image_url":"http://tp4.sinaimg.cn/1790486583/50/1281325895", "domain":"yymyzm", "gender":"f", "followers_count":5, "friends_count":4, "statuses_count":7, "favourites_count":0, "created_at":"Mon Aug 09 00:00:00 +0800 2010", "following":false, "allow_all_act_msg":false, "geo_enabled":false, "verified":false } } ]
字段说明 - 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标示,是否微博认证用户
使用示例
- xml:
curl -u user:password http://api.t.sina.com.cn/direct_messages/sent.xml
- json:
curl -u user:password http://api.t.sina.com.cn/direct_messages/sent.json
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'].' ; '); }