'request' => '/1.1/media/subtitles/create.json',
'error' => 'Invalid json content in field subtitle_info.',

i am trying to create subtitles to the video using create endpoint but its returning above error
i tried both srt and txt format

//media data which i got after uploading file 
array(
     'media_id' => 1612407601043570689,
     'media_id_string' => '1612407601043570689',
     'media_key' => '7_1612407601043570689',
     'size' => 10162544,
     'expires_after_secs' => 86400,
     'processing_info' => 
    stdClass::__set_state(array(
       'state' => 'pending',
       'check_after_secs' => 1,
    )),
  ))
//data which i passed to creation endpoint 
 array (
    'media_id' => '1612407601043570689',
    'media_category' => 'TweetVideo',
    'subtitle_info' => 
    array (
      'subtitles' => 
      array (
        'media_id' => '1612407640474238976',
        'language_code' => 'EN',
        'display_name' => 'English',
      ),
    ),
  )

Does it work if you upload subtitles with twurl commands for example, as opposed to PHP?

Here are some commands to use: How to Add Subtitles to Twitter Videos via the API | by Umpire Auditor | Medium

1 Like

@IgorBrigadir unfortunately i can only stick with php laravel, thanks for the link i will read on it, can i get any sample srt file ?

@Ann19072221 ,

I’m not very familiar with PHP, but the data structure directly below the subtitle_info field is a map, not an array. So if your code is correct, it must be like below when your code is parsed.

{
    "subtitle_info": {
        "subtitles": [
            {
                "media_id": "captionId",
                "language_code": "",
                "display_name": ""
            }
        ]
    }
}
1 Like

@kato_shinya thanks for your time,
in doc the request structure is

{
      "media_id":"692797692624265216",
      "media_category":"TweetVideo",
      "subtitle_info": {
        "subtitles": [
          "media_id":"105195515189863968",
          "language_code":"EN", //The language code should be a BCP47 code (e.g. 'en", "sp"),
          "display_name":"English"
        ]
      }
    }

which is not a valid json.
so is it okay with two arrays?

@Ann19072221 ,

Official example is wrong about structure of subtitles field.

And your request must be:

{
      "media_id":"692797692624265216",
      "media_category":"TWEET_VIDEO",
      "subtitle_info": {
        "subtitles": [
            {
                "media_id":"105195515189863968",
                "language_code":"EN", //The language code should be a BCP47 code (e.g. 'en", "sp"),
                "display_name":"English"
            }
        ]
      }
    }
1 Like

Thanks @kato_shinya for pointing the clutch i fixed it also thanks @IgorBrigadir for your time, u also helped me to dive into more deep

solution

$media_type = mime_content_type($local_file_path);
            $subtitleMediaDetails = $connection->upload('media/upload', ['media' =>$local_file_path, 'media_type' =>$media_type, 'media_category'=> 'Subtitles'],true);
 $subtitleMedaiId = $subtitleMediaDetails->media_id;           
                if($subtitleMedaiId) {
                    $json = '{
                        "media_id":"'.$media->media_id.'", // uploaded video id 
                        "media_category":"TweetVideo",
                        "subtitle_info": {
                          "subtitles": [
                            { "media_id":"'.$subtitleMedaiId.'", //uploaded subtitle video id
                              "language_code":"EN",
                              "display_name":"English"
                            }
                          ]
                        }
                      }';

                    $metadata_payload = json_decode($json, true);
                    $connection->setTimeouts(60, 60);
                    $createdSubritleResponse = $connection->post('media/subtitles/create', $metadata_payload, true); 
                }


2 Likes