Twitter api upload image always return error “media type unrecognized”

谁都会走 提交于 2021-02-04 08:15:24

问题


I do POST-request on https://upload.twitter.com/1.1/media/upload.json with postfield

'media_data' => base64_encode(file_get_contents($path))

twitter api always return error "media type unrecognized".

what's wrong?

I tried to change postfield to those versions:

'media_data' => 'data:image/'.$type.';base64,' . base64_encode(file_get_contents($path)),
'media' => file_get_contents($path),
'media' => realpath($path)...

file formats: jpeg, jpg


回答1:


I'm not sure why media wasn't working for you, but media_data has to be used without the header. I've used it this way and it works.

'media_data' => base64_encode(file_get_contents($path));

https://github.com/J7mbo/twitter-api-php/blob/1.0.5/test/TwitterAPIExchangeTest.php#L174-L181



来源:https://stackoverflow.com/questions/31536867/twitter-api-upload-image-always-return-error-media-type-unrecognized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!