I can't send a tweet with media
Closed this issue · 2 comments
Sharing as Text works, but I couldn't send a tweet with Media. I also did the validation for v1.1. Even when uploading the chris.png file in the file, I get an error like image formats. I don't quite understand. Is there a sample tweet code blog with an example image?
Iget Uncaught GuzzleHttp\Exception\ClientException error.
Hi, can you show me the code you're using?
Here is my code:
`$twitter = new \Coderjerk\BirdElephant\BirdElephant($config);
try {
// First, use the tweets()->upload method to upload your image file
$image = $twitter->tweets()->upload('./images/bg.jpg');
echo "Image uploaded: {$image->media_id_string}\n";
} catch (\Exception $e) {
echo 'An error occurred during the image upload process: ', $e->getMessage(), "\n";
exit;
}
// Pass the returned media id as an array to a media object
$media = (new \Coderjerk\BirdElephant\Compose\Media)->mediaIds(
[
$image->media_id_string
]
);
// Create the tweet and pass the media object, modifying the text as suggested by the producer
$text = "Test tweet @username";
$tweet = (new \Coderjerk\BirdElephant\Compose\Tweet)->text($text)
->media($media);
try {
$response = $twitter->tweets()->tweet($tweet);
echo "Tweet successfully posted!";
} catch (\Exception $e) {
echo 'An error occurred during the tweet posting process: ', $e->getMessage(), "\n";
}`
Error:
Image uploaded: 1648978594092179459 An error occurred during the tweet posting process: Client error:
POST https://api.twitter.com/2/tweets` resulted in a 400 Bad Request
response: {"errors":[{"parameters":{"media.media_ids":["1648978594092179459"]},"message":"Your media IDs are invalid."}],"title":" (truncated...)
`