Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - Twitter api upload image always return error "media type unrecognized"

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...