1

我在https://upload.twitter.com/1.1/media/upload.json 上使用 postfield进行 POST 请求

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

twitter api 总是返回错误“无法识别的媒体类型”。

怎么了?

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

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

文件格式:jpeg、jpg

4

1 回答 1

1

我不确定为什么media不适合你,但media_data必须在没有标题的情况下使用。我已经以这种方式使用它并且它有效。

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

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

于 2015-08-08T00:07:44.003 回答