abraham/twitteroauth

Media IDs Are Invalid

ProdigyView opened this issue · 1 comments

I am uploading a video to Twitter's API, but I get the error message Your media IDs are invalid. My Code:

<?php

require "vendor/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;


$connection = new TwitterOAuth('xxxx', 'xxxx', 'xxxxx', 'xxxxx');

$connection->setApiVersion(1.1);
$connection->setTimeouts(10, 15);

$media1 = $connection->upload('media/upload', ['media' => '/code/test.mp4','media_type' => 'video/mp4', 'media_category' => 'tweet_video'], ['chunkedUpload' => true]);

print_r($media1);

$connection->setApiVersion(2);
$parameters = [
    'text' => 'Meow Meow Meow',
    'media' => ['media_ids' => [$media1->media_id_string]]
];
$result = $connection->post('tweets', $parameters);

print_r($result);

And the output:

stdClass Object
(
    [media_id] => 1757063824702574592
    [media_id_string] => 1757063824702574592
    [media_key] => 7_1757063824702574592
    [size] => 8707460
    [expires_after_secs] => 86400
    [processing_info] => stdClass Object
        (
            [state] => pending
            [check_after_secs] => 1
        )

)
stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [parameters] => stdClass Object
                        (
                            [media.media_ids] => Array
                                (
                                    [0] => 1757063824702574592
                                )

                        )

                    [message] => Your media IDs are invalid.
                )

        )

    [title] => Invalid Request
    [detail] => One or more parameters to your request was invalid.
    [type] => https://api.twitter.com/2/problem

What am I doing wrong here?

[processing_info] => stdClass Object
        (
            [state] => pending
            [check_after_secs] => 1
        )

It looks like you have to wait until state is succeeded.

https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/get-media-upload-status