Twitter api 上传图片总是返回错误“媒体类型无法识别";

2022-01-09 00:00:00 twitter upload php twitter-rest-api

我在 https://upload.twitter.com/1.1/上进行 POST 请求媒体/上传.json带邮局

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

twitter api 总是返回错误媒体类型无法识别".

twitter api always return error "media type unrecognized".

怎么了?

我尝试将 postfield 更改为这些版本:

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)...

文件格式:jpeg、jpg

file formats: jpeg, jpg

推荐答案

我不知道为什么 media 不适合你,但 media_data 必须是不带标题使用.我用过这种方法,而且效果很好.

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

相关文章