Direct messages

跳转到: 导航, 搜索
 
(未显示6个用户的11个中间版本)
第1行: 第1行:
== direct_messages ==
+
{{api_desc2|
返回用户的最新20条私信。XML和JSON的版本有发送者和接受者的详细资料。
+
uri=direct_messages|
 
+
desc=返回登录用户的最新收到的n条私信,每条私信包含发送者和接受者的详细信息。|
Returns a list of the 20 most recent direct messages sent to the authenticating user.  The XML and JSON versions include detailed information about the sending and recipient users.
+
format=XML/JSON|
 
+
httpMethod=GET|
=== URL===
+
needAuth=true|
curl http://api.t.sina.com.cn/direct_messages.format
+
rateLimit=true|
+
params={{api_args|since_id|false|int64|若指定此参数,则只返回ID比since_id大的记录(比since_id发送时间晚)。}}
=== 格式===
+
{{api_args|max_id|false|int64|若指定此参数,则返回ID小于或等于max_id的记录}}
xml, json, rss, atom
+
{{api_args|count|false|int,默认值20,最大值200。|单页返回的记录条数。}}
+
{{api_args|page|false|int,默认值1。|返回结果的页码。}}|
=== HTTP请求方式===
+
getParam=&count=5&page=2|
GET
+
postParam=|
+
result=
=== 是否需要身份验证===
+
===XML示例===
true
+
<pre>
 
+
<?xml version="1.0" encoding="UTF-8"?>
=== 请求数限制===
+
1 call per request
+
 
+
=== 请求参数===
+
* since_id. 可选参数.  返回ID比数值since_id大(比since_id时间晚的)的私信。
+
o Example: http://api.t.sina.com.cn/direct_messages.xml?since_id=12345
+
* max_id. 可选参数.  返回ID不大于max_id(时间不晚于max_id)的私信。
+
o Example: http://api.t.sina.com.cn/direct_messages.xml?max_id=54321
+
* count.  可选参数.  每次返回的最大记录数(即页面大小),不大于200。 
+
o Example: http://api.t.sina.com.cn/direct_messages.xml?count=200
+
* page.  可选参数. 返回结果的页序号。注意:有分页限制。
+
o Example: http://api.t.sina.com.cn/direct_messages.xml?page=3
+
 
+
=== 返回 ===
+
XML示例:<?xml version="1.0" encoding="UTF-8"?>
+
 
<direct-messages>
 
<direct-messages>
 
   <direct_message>
 
   <direct_message>
     <created_at>Thu Jan 07 16:20:52 +0800 2010</created_at>
+
     <created_at>Fri Dec 03 14:30:01 +0800 2010</created_at>
     <id>207659</id>
+
     <id>710275891</id>
     <text>send</text>
+
     <text>你参加的 "圈内招聘" 微群( http://sinaurl.cn/hbPhiL )被设置为 封闭 群组</text>
     <sender_id>10506</sender_id>
+
     <sender_id>1821898647</sender_id>
     <recipient_id>11075</recipient_id>
+
     <recipient_id>1658122963</recipient_id>
     <sender_screen_name>name_10506</sender_screen_name>
+
     <sender_screen_name>微群小助手</sender_screen_name>
     <recipient_screen_name>name_11075</recipient_screen_name>
+
     <recipient_screen_name>zhangwei217245</recipient_screen_name>
 
     <sender>
 
     <sender>
       <id>10506</id>
+
       <id>1821898647</id>
       <screen_name>name_10506</screen_name>
+
       <screen_name>微群小助手</screen_name>
       <name>name_10506</name>
+
       <name>微群小助手</name>
       <province>0</province>
+
       <province>11</province>
       <city>0</city>
+
       <city>8</city>
       <location></location>
+
       <location>北京 海淀区</location>
       <description></description>
+
       <description>新浪微群官方帐号!顶部导航【微群】可直接进入微群页面。您有任何意见或者建议,可随时@微群小助手 私信完全开放。合作或疑问请联系13810888467</description>
       <profile_image_url>http://tp3.sinaimg.cn/10506/50/0</profile_image_url>
+
      <url>http://q.t.sina.com.cn/</url>
       <domain>10506</domain>
+
       <profile_image_url>http://tp4.sinaimg.cn/1821898647/50/1290508563/0</profile_image_url>
       <gender></gender>
+
       <domain/>
      <email></email>
+
       <gender>f</gender>
      <qq>5821</qq>
+
       <followers_count>6799</followers_count>
      <msn>msn_5821</msn>
+
       <friends_count>12</friends_count>
       <followers_count>24</followers_count>
+
       <statuses_count>53</statuses_count>
       <friends_count>50</friends_count>
+
       <favourites_count>0</favourites_count>
       <statuses_count>0</statuses_count>
+
       <created_at>Mon Sep 20 00:00:00 +0800 2010</created_at>
       <favourites_count>38</favourites_count>
+
       <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at>
+
 
       <following>false</following>
 
       <following>false</following>
       <verified>false</verified>
+
       <verified>true</verified>
       <geo_enabled>false</geo_enabled>
+
      <allow_all_act_msg>true</allow_all_act_msg>
 +
       <geo_enabled>true</geo_enabled>
 
     </sender>
 
     </sender>
 
     <recipient>
 
     <recipient>
       <id>11075</id>
+
       <id>1658122963</id>
       <screen_name>name_11075</screen_name>
+
       <screen_name>zhangwei217245</screen_name>
       <name>name_11075</name>
+
       <name>zhangwei217245</name>
       <province>0</province>
+
       <province>11</province>
       <city>0</city>
+
       <city>5</city>
       <location></location>
+
       <location>北京 朝阳区</location>
       <description></description>
+
       <description>ABCDE</description>
       <profile_image_url>http://tp4.sinaimg.cn/11075/50/0</profile_image_url>
+
      <url/>
       <domain>11075</domain>
+
       <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url>
       <gender></gender>
+
       <domain>zhangwei217245</domain>
      <email></email>
+
       <gender>m</gender>
      <qq>4102</qq>
+
       <followers_count>24</followers_count>
      <msn>msn_4102</msn>
+
       <friends_count>44</friends_count>
       <followers_count>28</followers_count>
+
       <statuses_count>118</statuses_count>
       <friends_count>50</friends_count>
+
       <favourites_count>3</favourites_count>
       <statuses_count>0</statuses_count>
+
       <created_at>Tue Nov 03 00:00:00 +0800 2009</created_at>
       <favourites_count>31</favourites_count>
+
       <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at>
+
 
       <following>false</following>
 
       <following>false</following>
       <verified>true</verified>
+
       <verified>false</verified>
       <geo_enabled>false</geo_enabled>
+
       <allow_all_act_msg>false</allow_all_act_msg>
 +
      <geo_enabled>true</geo_enabled>
 
     </recipient>
 
     </recipient>
 
   </direct_message>
 
   </direct_message>
 
   ...
 
   ...
  </direct-messages>
+
</direct-messages>
 
+
</pre>
JSON:示例
+
===JSON示例===
 
+
<pre>
  [
+
[
  {"created_at":"Thu Jan 07 16:20:52 +0800 2010",
+
    {
    "id":207659,
+
        "sender_screen_name" : "微群小助手",
    "text":"send 退出中共的党 9998888888888888888888888888 dm",
+
        "recipient_screen_name" : "zhangwei217245",
    "sender_id":10506,
+
        "text" : "你参加的 \"圈内招聘\" 微群( http://sinaurl.cn/hbPhiL )被设置为 封闭 群组",
    "recipient_id":11075,
+
        "recipient" :  
    "sender_screen_name":"name_10506",
+
        {
    "recipient_screen_name":"name_11075",
+
            "name" : "zhangwei217245",
    "sender":
+
            "domain" : "zhangwei217245",
          {"id":10506,
+
            "geo_enabled" : true,
             "screen_name":"name_10506",
+
            "followers_count" : 24,
             "name":"name_10506",
+
            "statuses_count" : 118,
             "province":"0",
+
            "favourites_count" : 3,
             "city":"0",
+
             "city" : "5",
             "location":"",
+
             "description" : "ABCDE",
             "description":"",
+
             "verified" : false,
             "profile_image_url":"http://tp3.sinaimg.cn/10506/50/0",
+
            "id" : 1658122963,
             "domain":"10506",
+
             "gender" : "m",
             "email":"",
+
             "friends_count" : 44,
             "qq":"5821",
+
            "screen_name" : "zhangwei217245",
             "msn":"msn_5821",
+
             "allow_all_act_msg" : false,
             "followers_count":24,
+
            "following" : false,
             "friends_count":50,
+
            "url" : "",
             "statuses_count":0,
+
             "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213",
             "favourites_count":38,
+
             "created_at" : "Tue Nov 03 00:00:00 +0800 2009",
             "created_at":"Thu Jan 01 08:00:00 +0800 1970",
+
             "province" : "11",
             "following":false,
+
             "location" : "北京 朝阳区"
            "geo_enabled":false,
+
        },
             "verified":false},
+
        "sender" :
    "recipient":
+
        {
          {"id":11075,
+
             "name" : "微群小助手",
             "screen_name":"name_11075",
+
             "domain" : "",
             "name":"name_11075",
+
             "geo_enabled" : true,
             "province":"0",
+
            "followers_count" : 6799,
             "city":"0",
+
             "statuses_count" : 53,
             "location":"",
+
             "favourites_count" : 0,
             "description":"",
+
             "city" : "8",
             "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0",
+
             "description" : "新浪微群官方帐号!顶部导航【微群】可直接进入微群页面。您有任何意见或者建议,可随时@微群小助手 私信完全开放。合作或疑问请联系13810888467",
             "domain":"11075",
+
             "verified" : true,
            "email":"",
+
            "id" : 1821898647,
             "qq":"4102",
+
             "gender" : "f",
             "msn":"msn_4102",
+
             "friends_count" : 12,
            "followers_count":28,
+
             "screen_name" : "微群小助手",
            "friends_count":50,
+
             "allow_all_act_msg" : true,
            "statuses_count":0,
+
             "following" : false,
            "favourites_count":31,
+
             "url" : "http://q.t.sina.com.cn/",
            "created_at":"Thu Jan 01 08:00:00 +0800 1970",
+
             "profile_image_url" : "http://tp4.sinaimg.cn/1821898647/50/1290508563/0",
            "following":false,
+
             "created_at" : "Mon Sep 20 00:00:00 +0800 2010",
            "geo_enabled":false,
+
             "province" : "11",
            "verified":true}
+
             "location" : "北京 海淀区"
            },
+
        },
    {},
+
        "sender_id" : 1821898647,
    ...
+
        "recipient_id" : 1658122963,
  ]
+
        "id" : 710275891,
 
+
        "created_at" : "Fri Dec 03 14:30:01 +0800 2010"
=== 使用示例===
+
    },
cURL:
+
...
 
+
]
* xml:
+
</pre>
 
+
{{param_DM}}
curl -u user:password http://api.t.sina.com.cn/direct_messages.xml
+
{{param_user}}|
 
+
useAge=无|
* json:
+
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
package weibo4j.examples;
 +
 +
import weibo4j.DirectMessage;
 +
import weibo4j.Weibo;
 +
import weibo4j.WeiboException;
 +
import java.util.List;
 +
 +
public class GetDirectMessages{
 +
 +
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.getDirectMessages();
 +
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 | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>
 +
代码示例如下:
 +
<pre>
 +
//direct_messages
 +
$c = new WeiboClient( WB_AKEY ,
 +
                      WB_SKEY ,
 +
                      $_SESSION['last_key']['oauth_token'] ,
 +
                      $_SESSION['last_key']['oauth_token_secret']  );
  
curl -u user:password http://api.t.sina.com.cn/direct_messages.json
+
$msg = $c->list_dm();
 +
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'].' ; ');
 +
}
 +
</pre>
 +
}}

2010年12月6日 (一) 10:58的最后版本

目录

direct_messages

返回登录用户的最新收到的n条私信,每条私信包含发送者和接受者的详细信息。

URL

http://api.t.sina.com.cn/direct_messages.(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>Fri Dec 03 14:30:01 +0800 2010</created_at>
    <id>710275891</id>
    <text>你参加的 "圈内招聘" 微群( http://sinaurl.cn/hbPhiL )被设置为 封闭 群组</text>
    <sender_id>1821898647</sender_id>
    <recipient_id>1658122963</recipient_id>
    <sender_screen_name>微群小助手</sender_screen_name>
    <recipient_screen_name>zhangwei217245</recipient_screen_name>
    <sender>
      <id>1821898647</id>
      <screen_name>微群小助手</screen_name>
      <name>微群小助手</name>
      <province>11</province>
      <city>8</city>
      <location>北京 海淀区</location>
      <description>新浪微群官方帐号!顶部导航【微群】可直接进入微群页面。您有任何意见或者建议,可随时@微群小助手 私信完全开放。合作或疑问请联系13810888467</description>
      <url>http://q.t.sina.com.cn/</url>
      <profile_image_url>http://tp4.sinaimg.cn/1821898647/50/1290508563/0</profile_image_url>
      <domain/>
      <gender>f</gender>
      <followers_count>6799</followers_count>
      <friends_count>12</friends_count>
      <statuses_count>53</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Mon Sep 20 00:00:00 +0800 2010</created_at>
      <following>false</following>
      <verified>true</verified>
      <allow_all_act_msg>true</allow_all_act_msg>
      <geo_enabled>true</geo_enabled>
    </sender>
    <recipient>
      <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>
    </recipient>
  </direct_message>
  ...
</direct-messages>

JSON示例

[
    {
        "sender_screen_name" : "微群小助手",
        "recipient_screen_name" : "zhangwei217245",
        "text" : "你参加的 \"圈内招聘\" 微群( http://sinaurl.cn/hbPhiL )被设置为 封闭 群组",
        "recipient" : 
        {
            "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" : 
        {
            "name" : "微群小助手",
            "domain" : "",
            "geo_enabled" : true,
            "followers_count" : 6799,
            "statuses_count" : 53,
            "favourites_count" : 0,
            "city" : "8",
            "description" : "新浪微群官方帐号!顶部导航【微群】可直接进入微群页面。您有任何意见或者建议,可随时@微群小助手 私信完全开放。合作或疑问请联系13810888467",
            "verified" : true,
            "id" : 1821898647,
            "gender" : "f",
            "friends_count" : 12,
            "screen_name" : "微群小助手",
            "allow_all_act_msg" : true,
            "following" : false,
            "url" : "http://q.t.sina.com.cn/",
            "profile_image_url" : "http://tp4.sinaimg.cn/1821898647/50/1290508563/0",
            "created_at" : "Mon Sep 20 00:00:00 +0800 2010",
            "province" : "11",
            "location" : "北京 海淀区"
        },
        "sender_id" : 1821898647,
        "recipient_id" : 1658122963,
        "id" : 710275891,
        "created_at" : "Fri Dec 03 14:30:01 +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 GetDirectMessages{

	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.getDirectMessages();
			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
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg = $c->list_dm();
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'].' ; ');
}
文档更新时间: 2010-12-06