Failed to create tweet with media - INVALID_MEDIA, Invalid media ids


#1

Hi everyone,

We are unable to create a tweet with an attached media. We tried using different aspect ratios with no luck. The error is not very descriptive, because we are using the same media id sent back to us. Also, it works flawlessly for website cards. Any insight will be greatly appreciated.

Media Request

Request DefaultHttpRequest(chunked: false)
POST /1.1/media/upload.json HTTP/1.1
Host: upload.twitter.com
Content-Type: multipart/form-data; boundary=zQK7qjpDvRQ0JIWN-zwVk-LIgTPFAacDpQc
Authorization: OAuth oauth_consumer_key=“HDgMOrYesLgvwbFl9ZzokSV4U”, oauth_nonce=“2635307337803476839”, oauth_signature=“3S19Ks36FbQi%2FSWA1TI%2BjxAnoYE%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1436492216”, oauth_token=“2262086336-Jn8EGzhDg84kdtiwiGcvjEh6mAvW9btgBb5ASQ9”, oauth_version="1.0"
Connection: keep-alive
Accept: /
User-Agent: NING/1.0
Content-Length: 799743

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-disposition: attachment; filename=json.json
content-length: 164
content-type: application/json;charset=utf-8
date: Fri, 10 Jul 2015 01:36:59 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Fri, 10 Jul 2015 01:36:59 GMT
pragma: no-cache
server: tsa_a
set-cookie: lang=en; Path=/
set-cookie: guest_id=v1%3A143649221958841024; Domain=.twitter.com; Path=/; Expires=Sun, 09-Jul-2017 01:36:59 UTC
status: 200 OK
strict-transport-security: max-age=631138519
vary: Origin
x-access-level: read-write
x-connection-hash: 5a31993f595ee41fc4064d2666776425
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 415
x-rate-limit-remaining: 409
x-rate-limit-reset: 1436494745
x-response-time: 118
x-transaction: 6a78c5ac78dfe074
x-tsa-request-body-time: 2540
x-twitter-response-tags: BouncerCompliant
x-xss-protection: 1; mode=block

2015-07-09 18:36:59,633 - [DEBUG] - from com.ning.http.client.providers.netty.NettyConnectionsPool in New I/O worker #70
Adding uri: https://upload.twitter.com:443 for channel [id: 0x3ea8527f, /192.168.2.4:57476 => upload.twitter.com/199.59.148.148:443]

2015-07-09 18:36:59,634 - [INFO] - from com.boostable.integration.twitter.service.TwitterAdService$ in play-akka.actor.default-dispatcher-13
200: {“media_id”:619319373254168580,“media_id_string”:“619319373254168580”,“size”:799466,“expires_after_secs”:3600,“image”:{“image_type”:“image/jpeg”,“w”:1200,“h”:628}}

Tweet Request

2015-07-09 18:37:02,770 - [INFO] - from com.boostable.integration.twitter.service.TwitterAdService$ in play-akka.actor.default-dispatcher-6
Create Tweet: twurl -H ads-api.twitter.com -d “status=Miniature Edge Lit Sign & Base - Buy Now! http://bit.ly/1HR1Trz&media_ids=619319373254168580” /0/accounts/18ce53zhjfq/tweet

Using cached Channel [id: 0x283f5564, /192.168.2.4:57472 => ads-api.twitter.com/199.59.149.200:443]
for request
DefaultHttpRequest(chunked: false)
POST /0/accounts/18ce53zhjfq/tweet HTTP/1.1
Host: ads-api.twitter.com
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Authorization: OAuth oauth_consumer_key=“HDgMOrYesLgvwbFl9ZzokSV4U”, oauth_nonce="-7719679248249728098", oauth_signature="%2FvpkvaY%2FZePhr79Bcyw30624PqE%3D", oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1436492222”, oauth_token=“18324461-ToirYi5Z7yKPPhFhM88aUAUsvNmE7YUBFmbdfVVWc”, oauth_version="1.0"
Connection: keep-alive
Accept: /
User-Agent: NING/1.0
Content-Length: 111

2015-07-09 18:37:03,100 - [DEBUG] - from com.ning.http.client.providers.netty.NettyAsyncHttpProvider in New I/O worker #69

Request DefaultHttpRequest(chunked: false)
POST /0/accounts/18ce53zhjfq/tweet HTTP/1.1
Host: ads-api.twitter.com
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Authorization: OAuth oauth_consumer_key=“HDgMOrYesLgvwbFl9ZzokSV4U”, oauth_nonce="-7719679248249728098", oauth_signature="%2FvpkvaY%2FZePhr79Bcyw30624PqE%3D", oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1436492222”, oauth_token=“18324461-ToirYi5Z7yKPPhFhM88aUAUsvNmE7YUBFmbdfVVWc”, oauth_version="1.0"
Connection: keep-alive
Accept: /
User-Agent: NING/1.0
Content-Length: 111

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 400 Bad Request
content-disposition: attachment; filename=json.json
content-length: 228
content-type: application/json;charset=utf-8
date: Fri, 10 Jul 2015 01:37:03 GMT
server: tsa_a
set-cookie: guest_id=v1%3A143649222286211833; Domain=.twitter.com; Path=/; Expires=Sun, 09-Jul-2017 01:37:03 UTC
strict-transport-security: max-age=631138519
x-access-level: read-write-directmessages
x-connection-hash: 63fb31c93dcb6ab15725b4c18478fd60
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 300
x-rate-limit-remaining: 296
x-rate-limit-reset: 1436492265
x-response-time: 313
x-runtime: 0.302202
x-transaction: b763bbab9a03489f
x-tsa-request-body-time: 0
x-xss-protection: 1; mode=block

2015-07-09 18:37:03,101 - [DEBUG] - from com.ning.http.client.providers.netty.NettyConnectionsPool in New I/O worker #69
Adding uri: https://ads-api.twitter.com:443 for channel [id: 0x283f5564, /192.168.2.4:57472 => ads-api.twitter.com/199.59.149.200:443]

2015-07-09 18:37:03,102 - [INFO] - from com.boostable.integration.twitter.service.TwitterAdService$ in play-akka.actor.default-dispatcher-8
400: {“errors”:[{“code”:“INVALID_MEDIA”,“message”:“Invalid media ids”}],“request”:{“params”:{“status”:“Miniature Edge Lit Sign & Base - Buy Now! http://bit.ly/1HR1Trz",“media_ids”:[619319373254168580],“account_id”:"18ce53zhjfq”}}}


#2

Hey there,
The media upload and tweet creation requests both look like they’re being made correctly, so the issue definitely requires more investigation.

  • Is this error occurring for all requests on this endpoint that contain media, or only for certain images?
  • Could you provide us an example of media that is causing trouble?

#3

Hi Helen,

We are experiencing this issue for all requests. However, we have been able to push tweets with attached media before for the @boostable ad account. Attaching one of the images we are trying to upload. Also we were able to successfully create a tweet with this image in the Twitter Ads console (for @boostable again).

Kunal


#4

Hmm, that’s odd. That media is working perfectly for me as for upload and promoted tweet creation. Occasionally, the returned MEDIA_ID is different from the returned MEDIA_ID_STRING, so I do recommend always making sure you’re using the MEDIA_ID_STRING value.

I do see that this isn’t true for your example above, but one additional note is that uploaded media expires after an hour, so that could be the source of the issue in some cases.


#5

Hey @hwz ,

Thank you for looking into this. We definitely can switch to using MEDIA_ID_STRING but we actually create the ads immediately to avoid any latency issues. Is there anything else we can check here?

Thank you so much for your help!
Rick


#6

Ok, will switch over to using media_id_string but it’s not unblocking us from launching tweets currently.

I don’t think it’s a timing issue either because we are creating media and tweet together (tweet after media).


#7

Helen, just an observation… We are able to consistently create tweets for @boostable, do you think it could be ad account / white list related?


#8

@spacer59 if the media id is indeed valid and hasn’t expired (> 1hr) then you at least won’t get the same error message you were seeing above. If you were running into a permission issue you would see a 403 response, 400s are invalid client requests (malformed or invalid requests).

If you’ve switched to media_id_string and you now see a different error message that you don’t understand please post the the full request and response here so we can trouble shoot it.


#9

Hi Brandon,

Following is a request made using media_id_string instead of media_id (includes timestamps). We are receiving an identical response. I am not aware of other circumstances that could qualify the media as invalid (maybe aspect ratio?).

Also, the same image / request pattern works for @boostable .

Media

Request DefaultHttpRequest(chunked: false)
POST /1.1/media/upload.json HTTP/1.1
Host: upload.twitter.com
Content-Type: multipart/form-data; boundary=ceXd_gTZzhdx70YfZ0iihUjnZFAp3Bl4rRItcap
Authorization: OAuth oauth_consumer_key=“HDgMOrYesLgvwbFl9ZzokSV4U”, oauth_nonce="-7080652278201630040", oauth_signature=“F%2FNz5UFbxh5TX5y55ytoFjywOJw%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1436980399”, oauth_token=“2262086336-Jn8EGzhDg84kdtiwiGcvjEh6mAvW9btgBb5ASQ9”, oauth_version="1.0"
Connection: keep-alive
Accept: /
User-Agent: NING/1.0
Content-Length: 71120

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-disposition: attachment; filename=json.json
content-length: 162
content-type: application/json;charset=utf-8
date: Wed, 15 Jul 2015 17:13:20 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Wed, 15 Jul 2015 17:13:20 GMT
pragma: no-cache
server: tsa_a
set-cookie: lang=en; Path=/
set-cookie: guest_id=v1%3A143698040012607046; Domain=.twitter.com; Path=/; Expires=Fri, 14-Jul-2017 17:13:20 UTC
status: 200 OK
strict-transport-security: max-age=631138519
vary: Origin
x-access-level: read-write
x-connection-hash: 78803e034e88f3d9e6f8a332532b2f3c
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 415
x-rate-limit-remaining: 408
x-rate-limit-reset: 1436982927
x-response-time: 82
x-transaction: 59bffbdee63960ab
x-tsa-request-body-time: 665
x-twitter-response-tags: BouncerCompliant
x-xss-protection: 1; mode=block

2015-07-15 10:13:20,148 - [DEBUG] - from com.ning.http.client.providers.netty.NettyConnectionsPool in New I/O worker #19
Adding uri: https://upload.twitter.com:443 for channel [id: 0x8660530e, /192.168.2.4:54022 => upload.twitter.com/199.59.148.213:443]

2015-07-15 10:13:20,149 - [INFO] - from com.boostable.integration.twitter.service.TwitterAdService$ in play-akka.actor.default-dispatcher-5
200: {“media_id”:621366950686359552,“media_id_string”:“621366950686359552”,“size”:70835,“expires_after_secs”:3600,“image”:{“image_type”:“image/jpeg”,“w”:380,“h”:379}}

Tweet

Request DefaultHttpRequest(chunked: false)
POST /0/accounts/18ce53zhjfq/tweet HTTP/1.1
Host: ads-api.twitter.com
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Authorization: OAuth oauth_consumer_key=“HDgMOrYesLgvwbFl9ZzokSV4U”, oauth_nonce="-2134622370024640928", oauth_signature=“FG90%2Fbp4QhGsa%2B01xOQvEKktjLA%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1436980403”, oauth_token=“18324461-ToirYi5Z7yKPPhFhM88aUAUsvNmE7YUBFmbdfVVWc”, oauth_version="1.0"
Connection: keep-alive
Accept: /
User-Agent: NING/1.0
Content-Length: 111

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 400 Bad Request
content-disposition: attachment; filename=json.json
content-length: 228
content-type: application/json;charset=utf-8
date: Wed, 15 Jul 2015 17:13:23 GMT
server: tsa_a
set-cookie: guest_id=v1%3A143698040345390253; Domain=.twitter.com; Path=/; Expires=Fri, 14-Jul-2017 17:13:23 UTC
strict-transport-security: max-age=631138519
x-access-level: read-write
x-connection-hash: a6391768ae474548c4509d3c78bc61ec
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 300
x-rate-limit-remaining: 296
x-rate-limit-reset: 1436980439
x-response-time: 79
x-runtime: 0.07071
x-transaction: a2b4f46ef8f9bb05
x-tsa-request-body-time: 0
x-xss-protection: 1; mode=block

2015-07-15 10:13:23,453 - [DEBUG] - from com.ning.http.client.providers.netty.NettyConnectionsPool in New I/O worker #18
Adding uri: https://ads-api.twitter.com:443 for channel [id: 0xc2e21038, /192.168.2.4:54018 => ads-api.twitter.com/199.59.148.84:443]

2015-07-15 10:13:23,454 - [INFO] - from com.boostable.integration.twitter.service.TwitterAdService$ in play-akka.actor.default-dispatcher-2
400: {“errors”:[{“code”:“INVALID_MEDIA”,“message”:“Invalid media ids”}],“request”:{“params”:{“status”:“Miniature Edge Lit Sign & Base - Buy Now! http://bit.ly/1I2PuAP",“media_ids”:[621366950686359552],“account_id”:"18ce53zhjfq”}}}


#10

Any updates here? This is still blocking us from launching Tweets.


#11

Hey @hwz & @brandonmblack,

Just checking in here. We are currently blocked from launching any tweets with images for our merchants. We were told that they are the best type of placement for Direct Response campaigns. Is there anything else we can try here to get Tweets through from Boostable to our merchants Twitter handles?

To simplify the problem - when we launch tweets for the Boostable handle it works but when we launch tweets for merchants nothing goes through. It seems that Boostable’s handle was whitelabeled but the new accounts are not. Maybe any account with our PMFI attached to it could be whitelabeled to send Tweets?

Thank you for your help!
Rick


#12

Hi Rick, thanks for the additional details.

Posting tweets with images is a feature that is allowed for all ads accounts, so it is definitely not an issue of whitelisting.

I do want to make sure – are you able to use the Ads API tweet endpoint to create tweets without attached media for your advertisers?


#13

Hi Helen,

Just verified we are able to create tweets without media.

Request

[info] c.b.i.t.s.TwitterAdService$ - Create Tweet: twurl -H ads-api.twitter.com -d “status=Miniature Edge Lit Sign & Base for only $169.99! Buy Now! https://cards.twitter.com/cards/18ce53zhjfq/qj7u” /0/accounts/18ce53zhjfq/tweet

Truncated response

[info] c.b.i.t.s.TwitterAdService$ - 200: {“data_type”:“status”,“data”:{“created_at”:“Fri Jul 17 21:09:37 +0000 2015”,“id”:622151189015105536,“id_str”:“622151189015105536”,“text”:“Miniature Edge Lit Sign & Base for only $169.99! Buy Now! https://t.co/jo7pHBbYWJ”,“source”:"<a href=“http://www.boostable.com/” rel=“nofollow”>Boostable",“truncated”:false,“in_reply_to_status_id”:null,“in_reply_to_status_id_str”:null,“in_reply_to_user_id”:null,“in_reply_to_user_id_str”:null,“in_reply_to_screen_name”:null,“user”:{“id”:18324461,"id_

Thanks and le me know if you need more info.


#15

An important constraint is that unless other user ids are passed to the media/upload endpoint as additional_owners, only the user uploading the media will be able to use the uploaded media.

You might need to make use of the additional_owners parameter on the upload/media endpoint, and the as_user_id parameter on the tweet endpoint if tweet delegation is involved.


#16

Thanks Helen, that seemed to do the trick. Never used Tweet delegation, when is it an appropriate function?


#17

Great! I’m glad to hear that this did the trick! I’ll be closing this topic now.

When I say tweet delegation, I simply mean when posting tweets on behalf of another user (for instance, an ad manager). Nothing too complicated!


#18