Using API1.1, I’m not able to post an update with an image. I think it is due to improperly signing the request… but I’m not sure. Using v1.1, POST, multipart data. Anyone know why this is happening? Please help!
Using the Twitter Developer Console results in a successful tweet with image.
Authorization request is successful however the subsequent update_with_media post returns the following error (using Fiddler)
Response
HTTP/1.1 401 Unauthorized
code=32
message=Could not authenticate you
The raw request is:
Request
POST https://api.twitter.com/1.1/statuses/update_with_media.json HTTP/1.1
Referer: app:/twitterTest.swf
Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, */*;q=0.5
x-flash-version: 11,7,700,224
Content-Type: multipart/form-data, boundary=----------gL6ae0cH2Ef1Ij5GI3gL6GI3GI3ei4
X-Target-URI: https://api.twitter.com
Mime-Version: 1.0
X-HostCommonName: api.twitter.com
Authorization: OAuth oauth_consumer_key="{removed}", oauth_nonce="51915", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1390591324", oauth_token="{removed}", oauth_version="1.0", oauth_signature="{removed}"
Content-Length: 21692
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (Windows; U; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/3.7
Host: api.twitter.com
Connection: Keep-Alive
Cookie: guest_id=v1%3A138385821369315395; twll=l%3D1388514403; remember_checked=1; remember_checked_on=1; auth_token={removed}; secure_session=true; _twitter_sess=BAh7CToJdXNlcmkEXqxRHzoMY3NyZl9pZCIlNzcxNTliYzI4ODcxZjgzNjdi%250AYTJkYzJiMjU5MDY3NTg6B2lkIiU1MGVhZDhmNzYwZTcyODNiYTcwODIxODEx%250AMjdjMTllZDoPY3JlYXRlZF9hdGwrCFRWs8VDAQ%253D%253D--5ab20358d362c078fe03735acb98502695935ffe; twid=u%3D525446238%7CcJyhNJqYbXpS4mVk64IVAiEBVAk%3D; __utma=191792890.63151085.1383861162.1383861162.1383861162.1; __utmz=191792890.1383861162.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); external_referer=fJs6%2Fry34fDpYITA3edMEbH0DKq7KyB4%7C0; lang=en
------------gL6ae0cH2Ef1Ij5GI3gL6GI3GI3ei4
Content-Disposition: form-data; name="status"
This is a test @tester #testStatus>
------------gL6ae0cH2Ef1Ij5GI3gL6GI3GI3ei4
Content-Disposition: form-data; name="media[]"; filename="006c.JPG"
Content-Type: image/jpeg
����� JFIF� �� � �������
{truncated}
The code being used to build the request is AS3 using AIR:
public function updateStatusWithMedia(status:String, imageData:BitmapData):void
{
var boundary:String = "----------gL6ae0cH2Ef1Ij5GI3gL6GI3GI3ei4";
var vars:URLVariables = new URLVariables();
vars.status = strEscape(status.substr(0,140));
checkCredentials();
request = URL_SEND_UPDATE_WITH_MEDIA;
_returnType = RETURN_TYPE_STATUS;
var imageByteArray:ByteArray = new ByteArray();
var aJPGEncoder:JPGEncoder = new JPGEncoder();
imageByteArray = aJPGEncoder.encode(imageData);
var mfd:MultipartFormData=new MultipartFormData(boundary);
mfd.addData("status",status);
mfd.addData("media[]",imageByteArray, "006c.JPG", "image/jpeg");
var urlRequest2 : URLRequest = new URLRequest();
var signedData:String = _oAuth.getSignedRequestForHeader( URLRequestMethod.POST, "https://api.twitter.com/1.1/statuses/update_with_media.json", null );
var authHeader : URLRequestHeader = new URLRequestHeader("Authorization", "OAuth " + signedData);
var headers : Array = new Array();
headers.push(authHeader);
headers.push(getHostCommonNameHeader());
headers.push(getMimeHeader());
headers.push(new URLRequestHeader("X-Target-URI", "https://api.twitter.com"));
urlRequest2.requestHeaders = headers;
urlRequest2.url = serviceHost + request;
urlRequest2.contentType = "multipart/form-data, boundary=" + mfd.boundary;
urlRequest2.data = mfd.getByteArray();
urlRequest2.method = URLRequestMethod.POST;
urlLoader.load(urlRequest2);
}