Hi ,
i am trying to upload is 317kb in size & i follow video upload document of twitter & i have integrate to php twitteroauth library but i have got error "segment do not add up to provided total file size ".
This is the function i have written.
require('twitteroauth/autoload.php');
include_once APPPATH."libraries/twitter-oauth-php-codexworld/twitteroauth.php";
$consumerKey = 'XXXXXXXXXXXX';
$consumerSecret = 'XXXXXXXXXXXXXXXXXXXXX';
$tw_access_token = '755037110134902787-XXXXXXXXXXX';
$tw_secret_key = XXXXXXXXXX';
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $tw_access_token , $tw_secret_key);
$filename = 'http://app.socialwithease.com/video/test3.mp4';
$headers = get_headers($filename, 1);
$a = array(
'command'=>'INIT',
'total_bytes'=>$headers['Content-Length'],
'media_type' => 'video/mp4',
'media_category'=>'tweetvideo',
);
$tweetWM = $connection->upload('media/upload', $a);
$fp = fopen($img_url, 'r');
$segment_id = 0;
while (! feof($fp)) {
$chunk = fread($fp, 1048576); // 1MB per chunk for this sample
$b = array(
'command'=>'APPEND',
'media_id'=>$tweetWM->media_id,
'media'=>$img_url,
'segment_index' => $segment_id
);
$tweetWM1 = $connection->upload('media/upload', $b);
$segment_id++;
}
$c = array(
'command'=>'FINALIZE',
'media_id'=>$tweetWM->media_id,
);
$tweetWM2 = $connection->upload('media/upload', $c);
var_dump($tweetWM2);
$tweet = $connection->post('statuses/update', ['media_ids' =>$tweetWM2->media_id,'status' => "Test Video Upload"]);
print_r($tweet);
Please tell me how to set segment index of file size.