Statuses/upload/en

Jump to: navigation, search

Contents

statuses/upload

Update a picture weibo, request must be handed in POST method (Note encode the data with multipart/form-data). Currently the size of the picture has a 5MB limitation.

URL

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

Supported Formats

XML/JSON

HTTP Request Method

POST

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)
status true string Weibo content to be update
pic true binary Picture to be uploaded. Only support JPEG, GIF, PNG formats.Returns 400 error if the parameter is null.Currently the size of uploading picture has a 5MB limitation.
lat false float Latitude. Range: -90.0 to + 90.0. + stands for Norht latitude.
long false float Longitude. Range: -180.0 to + 180.0. + stands for East Longitude.
Notes: lat and long need to be used in conjunction with. They’re used to mark the geographical location when the weibo is updated. It is only activated when geo_enabled=true in the user setting.

Notes

  • Using multipart/form-data encoding, see Form-based File Upload in HTML, the 6th paragraph: Examples
  • If Oauth cetificaiton is used, picture parameter pic does not participate in the signature.

Example Request

XML
curl -u "username:password" -F "pic=@1.png" -F "status=share picture" "http://api.t.sina.com.cn/statuses/upload.xml?source=appkey"
JSON
curl -u "username:password" -F "pic=@1.png" -F "status=share picture" "http://api.t.sina.com.cn/statuses/upload.json?source=appkey"

Response

XML Example

<?xml version="1.0" encoding="UTF-8"?>
  <status>
    <created_at>Thu Dec 02 17:02:42 +0800 2010</created_at>
    <id>4022982531</id>
    <text>abc</text>
    <source>
      <a href="http://open.t.sina.com.cn">微博开放平台接口</a>
    </source>
    <favorited>false</favorited>
    <truncated>false</truncated>
    <geo/>
    <in_reply_to_status_id></in_reply_to_status_id>
    <in_reply_to_user_id></in_reply_to_user_id>
    <in_reply_to_screen_name></in_reply_to_screen_name>
    <thumbnail_pic>http://ww3.sinaimg.cn/thumbnail/6b8527b3jw6dbydoikpzuj.jpg</thumbnail_pic>
    <bmiddle_pic>http://ww3.sinaimg.cn/bmiddle/6b8527b3jw6dbydoikpzuj.jpg</bmiddle_pic>
    <original_pic>http://ww3.sinaimg.cn/large/6b8527b3jw6dbydoikpzuj.jpg</original_pic>
    <user>
      <id>1803888563</id>
      <screen_name>LoopC</screen_name>
      <name>LoopC</name>
      <province>11</province>
      <city>8</city>
      <location>北京 海淀区</location>
      <description></description>
      <url></url>
      <profile_image_url>http://tp4.sinaimg.cn/1803888563/50/0</profile_image_url>
      <domain></domain>
      <gender>m</gender>
      <followers_count>1</followers_count>
      <friends_count>1</friends_count>
      <statuses_count>2</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Fri Aug 27 00:00:00 +0800 2010</created_at>
      <following>false</following>
      <verified>false</verified>
      <allow_all_act_msg>false</allow_all_act_msg>
      <geo_enabled>true</geo_enabled>
    </user>
  </status>

JSON Example

{

    "created_at": "Thu Dec 02 17:06:40 +0800 2010",
    "id": 4023064087,
    "text": "abc",
    "source": "微博开放平台接口",
    "favorited": false,
    "truncated": false,
    "in_reply_to_status_id": "",
    "in_reply_to_user_id": "",
    "in_reply_to_screen_name": "",
    "thumbnail_pic": "http://ww2.sinaimg.cn/thumbnail/6b85067djw6dbydsnam1xj.jpg",
    "bmiddle_pic": "http://ww2.sinaimg.cn/bmiddle/6b85067djw6dbydsnam1xj.jpg",
    "original_pic": "http://ww2.sinaimg.cn/large/6b85067djw6dbydsnam1xj.jpg",
    "geo": {
          "type": "Point",
          "coordinates": [
               39.8765,
               119.5678
            ]
      },
    "user":{
          "id": 1803880061,
          "screen_name": "LoopB",
          "name": "LoopB",
          "province": "11",
          "city": "8",
          "location": "北京 海淀区",
          "description": "",
          "url": "",
          "profile_image_url": "http://tp2.sinaimg.cn/1803880061/50/0/0",
          "domain": "",
          "gender": "f",
          "followers_count": 1,
          "friends_count": 1,
          "statuses_count": 14,
          "favourites_count": 4,
          "created_at": "Fri Aug 27 00:00:00 +0800 2010",
          "following": false,
          "allow_all_act_msg": false,
          "geo_enabled": true,
          "verified": false
      }
}

Others

Java Example

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

        public static void main(String[] args) {
		try {
			if (args.length < 3) {
	            System.out.println(
	                "Usage: java weibo4j.examples.OAuthUploadByFile token tokenSecret filePath");
	            System.exit( -1);
	        }
			
			System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
			System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);

			Weibo weibo = new Weibo();
			
			/*
			 * 此处需要填写AccessToken的key和Secret
                        */
			weibo.setToken(args[0], args[1]);
			try {
				File file=new File(args[2]);
				String msg = URLEncoder.encode("中文内容", "UTF-8");
				Status status = weibo.uploadStatus(msg, file);

				System.out.println("Successfully upload the status to ["
						+ status.getText() + "].");
				
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} catch (Exception ioe) {
			System.out.println("Failed to read the system input.");
		}
	}

PHP Example

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

<?php
$boundary = uniqid('------------------');
$MPboundary = '--'.$boundary;
$endMPboundary = $MPboundary. '--';

// 需要上传的图片所在路径
$filename = '/tmp/wiki.png';
$file = file_get_contents($filename);

$multipartbody .= $MPboundary . "\r\n";
$multipartbody .= 'Content-Disposition: form-data; name="pic"; filename="wiki.png"'. "\r\n";
$multipartbody .= 'Content-Type: image/png'. "\r\n\r\n";
$multipartbody .= $file. "\r\n";

$k = "source";
// 这里改成 appkey
$v = "appkey";
$multipartbody .= $MPboundary . "\r\n";
$multipartbody.='content-disposition: form-data; name="'.$k."\"\r\n\r\n";
$multipartbody.=$v."\r\n";

$k = "status";
$v = "要上传的文件,这里是描述文字";
$multipartbody .= $MPboundary . "\r\n";
$multipartbody.='content-disposition: form-data; name="'.$k."\"\r\n\r\n";
$multipartbody.=$v."\r\n";
$multipartbody .= "\r\n". $endMPboundary;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.t.sina.com.cn/statuses/upload.xml' );
curl_setopt($ch , CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$multipartbody );
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 修改成当前用户名及密码
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
$msg = curl_exec($ch);
//echo $multipartbody;
echo 'ok.';
?>

Other Language

Refer to the following tests: save the following codes in HTML, open this page can upload picture when weibo is authenticated. Modify your program by by comparing the parameters of the HTTP call sent by browser. (you can use HttpWatch, Firebug and other tools to monitor the HTTP transferring data). Note: replace the appkey with true value in the following codes.


 



文档更新时间: 20 January 2011