Jump to: navigation, search



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.


Supported Formats


HTTP Request Method


Requires Authentication

See the Authorization Mechanism Statement for authorization details

Requests Count Limitation

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.


  • 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

curl -u "username:password" -F "pic=@1.png" -F "status=share picture" ""
curl -u "username:password" -F "pic=@1.png" -F "status=share picture" ""


XML Example

<?xml version="1.0" encoding="UTF-8"?>
    <created_at>Thu Dec 02 17:02:42 +0800 2010</created_at>
      <a href="">微博开放平台接口</a>
      <location>北京 海淀区</location>
      <created_at>Fri Aug 27 00:00:00 +0800 2010</created_at>

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": "",
    "bmiddle_pic": "",
    "original_pic": "",
    "geo": {
          "type": "Point",
          "coordinates": [
          "id": 1803880061,
          "screen_name": "LoopB",
          "name": "LoopB",
          "province": "11",
          "city": "8",
          "location": "北京 海淀区",
          "description": "",
          "url": "",
          "profile_image_url": "",
          "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


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) {
	                "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) {
		} 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:

$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";

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

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '' );
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