Direct messages/en

跳转到: 导航, 搜索

目录

direct_messages

Return the latest N direct message of authenticating user. Each message contain the sender and recipient’s profile.

URL

http://api.t.sina.com.cn/direct_messages.(json%7Cxml)

Supported Formats

XML/JSON

HTTP Request Method

GET

Requires Authentication

true
See the Authorization Mechanism Statement for authorization details

Requests Count Limitation

true
See the Interface Access Rights Statement for the Request Count Limitaiton details.

Request Parameters

  Requires Type and Range Description
source true string AppKey for the application to identify it. ( This parameter is not needed when using OAuth)
since_id false int64 Returns then weibos with an ID greater than (that is, more recent than) the specified ID
max_id false int64 Return the weibos with an ID smaller than the specified ID.录
count false int, default is 20, max is 200. Specify the number of weibos return in one page.。
page false int, default is 1. Specify results page. Based on the number of the authenticating user’s followings and the number of the followings’s weibos, the max number of weibos that page feature can access is different, usually up to about 1000 piceces.。

Notes

None

Example Request

XML
curl -u "username:password" "http://api.t.sina.com.cn/direct_messages.xml?source=appkey&count=5&page=2"
JSON
curl -u "username:password" "http://api.t.sina.com.cn/direct_messages.json?source=appkey&count=5&page=2"

Response

XML Example

<?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 Example

[
    {
        "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"
    },
...
]

Field Description - direct_message

  • id: direct message ID
  • text: direct message content
  • sender_id:sender’s UID
  • recipient_id: revipient’s UID
  • created_at: created time
  • sender_screen_name: sender’s nickname
  • recipient_screen_name:recipient’s nickname
  • sender: sender’s profile, see user specification
  • recipient: recipient’s profile, see user specification

Field Description - user

  • id: User ID
  • screen_name: User’s nickname displayed on the home page
  • name: Friendly displayed name, the same as screen_name
  • province: Province code ( see Province and city code table)
  • city: City code ( see Province and city code table)
  • location:Address
  • description: Personal description
  • url: Url of the user’s blog
  • profile_image_url: Profile image
  • domain: The user’s personalized weibo url
  • gender: Gender, m—male, f- - female, n-- unknown
  • followers_count: Followers count
  • friends_count: Following count
  • statuses_count: Weibo count
  • favourites_count: Favorites count
  • created_at: Created time
  • following: Whether the current user is following the user that posts the weibo (Not supported yet)
  • verified: Whether the user is verified by his real identity, marked with “V”

Others

Java Example

Please download Java SDK from . Weibo SDK Development Kit Dowload Site
Sample Code:

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 Example

Please download PHP SDK with OAUTH supported from Weibo SDK Development Kit Dowload Site
. Sample Code:

//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'].' ; ');
}



文档更新时间: 2011-01-30