"error": "Invalid mediaId."


#1

Hi,
We’re trying to upload image. Did like this:

twurl -X POST -H upload.twitter.com "/1.1/media/upload.json?additional_owners={********}" --file /home/wangdao/TwitterSmartAdsTest/pic/female/twitter_20170301_all_female_me_product_carousel_042263042TD.jpg --file-field "media" | python -m json.tool

But when I want to get information,return error. Did like this:

twurl -H upload.twitter.com "/1.1/media/upload.json?command=STATUS&media_id=********" | python -m json.tool

then return error like this:

{
    "error": "Invalid mediaId.",
    "request": "/1.1/media/upload.json"
}

I did method like this post,but also cannot get something.
Can someone help me?


#2

Invalid media Id I did method like this post,but also return error.And the problem was closed.I want to know how to solve the problem


#3

Hi,
Did U ever solve this? I have this same problem.


#4

Can you describe what your code is doing? Are you using Javascript?


#5

Hi @andypiper,

I am using https://www.npmjs.com/package/twitter. I successfully post an image to /media/upload and save the media object below as mediaClient. Then I try to make a GET to the same endpoint to get the status but I get an error and invalid mediaId. I thought it might be timing error but it seems not.

One thing is the media_id and media_id_string are sometimes different. I’m trying to use the string version.

//from successful POST request
let mediaClient = {
	media_id: 1068551683716706300,
	media_id_string: '1068551683716706304',
	size: 311436,
	expires_after_secs: 86400,
	image: {
		image_type: 'image/png',
		w: 1536,
		h: 1544
	}
}
//for upcoming GET - uses media_id_string from above
let params = {
	command: 'STATUS',
	media_id: mediaClient.media_id_string
}
//logs { command: 'STATUS', media_id: '1068551683716706304' }

client.get('media/upload', params, function(error, upload, response) {
        if (error) console.error(error)
        
// Error: HTTP Error: 400 Bad Request
//     at Request._callback (/Users/me/desktop/code_work/vue/clock_html/app/node_modules/twitter/lib/twitter.js:221:9)
//     at Request.self.callback (/Users/me/desktop/code_work/vue/clock_html/app/node_modules/request/request.js:185:22)
//     at emitTwo (events.js:126:13)
//     at Request.emit (events.js:214:7)
//     at Request.<anonymous> (/Users/me/desktop/code_work/vue/clock_html/app/node_modules/request/request.js:1161:10)
//     at emitOne (events.js:116:13)
//     at Request.emit (events.js:211:7)
//     at IncomingMessage.<anonymous> (/Users/me/desktop/code_work/vue/clock_html/app/node_modules/request/request.js:1083:12)
//     at Object.onceWrapper (events.js:313:30)
//     at emitNone (events.js:111:20)
	console.log('worked?', upload)

      //logs worked? { request: '/1.1/media/upload.json', error: 'Invalid mediaId.' }

})

#6

The reason that the ids appear different is that you’re using Javascript - described here. This is expected. You’re correct to use the string version.

This is really weird, as I can see that specific media ID is valid internally, so I don’t understand how this is coming back as an invalid value.