Error Posting image post to Twitter

image

#1

I’m not able to create some image post with particular image urls.

E.g.

  1. Using https://s3.amazonaws.com/reputation-com-enterprise-prod/enterprise-assets%2FBeekeeper.jpg as the image url in a post, I got error like this:
    Something is broken at Twitter. Please see http://dev.twitter.com/pages/support

  2. Using other urls like http://www.rightmove.co.uk/news/wp-content/uploads/2016/05/know-the-rules-happy-296x197.jpg
    error:
    I/O error on POST request for “https://upload.twitter.com/1.1/media/upload.json”:Server returned HTTP response code: 403 for URL: http://www.rightmove.co.uk/news/wp-content/uploads/2016/05/know-the-rules-happy-296x197.jpg; nested exception is java.io.IOException: Server returned HTTP response code: 403 for URL:

  3. Using urls like https://s3.amazonaws.com/reputation-com-enterprise-prod/enterprise-assets%2Flincoln-navigator-concept.jpg
    error:
    Error consuming Twitter REST API

Not sure if these urls have violated any rules in the ‘Twitter POST media/upload’ ?


#2

Can you share examples of the code you’re using to upload? I wasn’t aware that the media upload endpoint supported arbitrary URLs as targets for ingest.


#3

Two steps:
Step one:
String MEDIA_UPLOAD = "https://upload.twitter.com/1.1/media/upload.json"
params:
“media” -> URL [http://www.rightmove.co.uk/news/wp-content/uploads/2016/05/know-the-rules-happy-296x197.jpg]
Map response = restTemplate.postForObject(MEDIA_UPLOAD, postParams, Map.class);
//Get media id here:
String mediaID = response.get(“media_id_string”);

Step two:
String STATUSES_UPDATE = “https://api.twitter.com/1.1/statuses/update.json”;
postParameters:
“status” -> “message”
“media_ids” -> mediaID
String id = restTemplate.postForObject(STATUSES_UPDATE, postParameters, Tweet.class);

For failure:
“I/O error on POST request for … Server returned HTTP response code: 403 for URL”, it failed at first step.
For failure:
“Error consuming Twitter REST API” and “Something is broken at Twitter. Please see http://dev.twitter.com/pages/support”, it failed at the second step. (Which means I can get a media id from the first step, and it shows successful in uploading)


#4

According to the API documentation, the media parameter should contain raw binary file content, not a URL.


#5

This is actually raw binary file content. We did some transfer in backend and it was actually a resource type but not pure String. (public interface Resource extends InputStreamSource)

Also just like I mentioned before, most of them are successfully uploaded in the MEDIA_UPLOAD process but failed at the second process STATUSES_UPDATE.


#6

Are you able to confirm that the files you are attempting to upload conform to the specification?

We’d need more information on the successful and failing posts to help to diagnose, I think. Can you narrow down specific test cases?


#7

Successful case:
http://www.reputation.com/repbizFiles/tenants/19/social/background_dq.jpg
"https://support.files.wordpress.com/2009/07/pigeony.jpg?w=688"
https://s3.amazonaws.com/reputation-com-enterprise-qa/enterprise-assets%2F1474310313482_bird_for_test.jpg

Failed cases:
https://s3.amazonaws.com/reputation-com-enterprise-prod/enterprise-assets%2FBeekeeper.jpg
http://www.rightmove.co.uk/news/wp-content/uploads/2016/05/know-the-rules-happy-296x197.jpg
https://s3.amazonaws.com/reputation-com-enterprise-prod/enterprise-assets%2Flincoln-navigator-concept.jpg


#8

Here’s the request

POST /1/statuses/update.json?include_entities=true HTTP/1.1
Accept: /
Connection: close
User-Agent: OAuth gem v0.4.4
Content-Type: application/x-www-form-urlencoded
Authorization:
/*
omit oauth data
*/
Content-Length: 76
Host: api.twitter.com

status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21&media_ids=790703260990439426

So one of the offending image is 790703260990439426.