PHP?twitterAPI???????????

PHP?Twitter API??????????????????

?????

Twitter???????media/upload?INIT?APPEND?FINALIZE?STATUS??
?????????????statuses/update??????????????

30??????????????APPEND??
???????????STATUS?????????????

?30????????????????????????

??

?Twitter??????????????????????????????
??????????????????????

?????????????????????????
>> Twitter Application Management

Consumer key,Consumer secret,Access Token,sAccessToken??????

????TwitterOAuth??????
???????????OAuth???????
>> TwitterOAuth

?PHP5.4??????
????????????????
phpinfo();??????

php5.4????????????????
TwitterOAuth.php on line 129

??????

//twitteroauth.php???????????????????????????????
require “twitteroauth/autoload.php”;
use Abraham\TwitterOAuth\TwitterOAuth;

//Consumer key?????
$sConsumerKey = “XXXXXXXXXXXXXXXXXXXXXXXXXX”;
//Consumer secret?????
$sConsumerSecret = “XXXXXXXXXXXXXXXXXXXXXXXXXX”;
//Access Token?????
$sAccessToken = “XXXXXXXXXXXXXXXXXXXXXXXXXX”;
//Access Token Secret?????
$sAccessTokenSecret = “XXXXXXXXXXXXXXXXXXXXXXXXXX”;

$to = new TwitterOAuth($sConsumerKey,$sConsumerSecret,$sAccessToken,$sAccessTokenSecret);

$filename = “img/test.mp4”;
$fileText = “??????????”;

$url = “https://upload.twitter.com/1.1/statuses/update.json”;
$uri = “https://upload.twitter.com/1.1/media/upload.json”;
$method = “POST”;

$segment_index = 0;
$chank = 5 * 1024 * 1024;

//?????????????????????
$file_date = file_get_contents($filename);
$file_date = base64_encode($file_date);
$file_size = mb_strlen($file_date);

//???????????????????????
$info = $to->OAuthRequest($uri,$method,array(‘command’ => ‘INIT’,’media_type’ => ‘video/mp4′,’total_bytes’ => filesize($filename), ‘media_category’ => ‘tweet_video’));
$Obj = json_decode($info);

//??????????
$sba = $Obj->media_id_string;

//????????????
$maxRound = ceil($file_size / $chank);

//APPEND???????????????????
for($i=0;$i<$maxRound;$i++){ $file_size_x[$i] = substr($file_date,$chank*$i,$chank); $to->OAuthRequest($uri,$method,array(‘command’ => ‘APPEND’,’media_id’ => $sba,’segment_index’ => $i,’media’ => $file_size_x[$i],));
}
$info = $to->OAuthRequest($uri,$method,array(‘command’ => ‘FINALIZE’,’media_id’ => $sba));
$Obj = json_decode($info);

//?????????????????????????????
for($i=0 ;$i<$maxRound ;$i++){ sleep($Obj->processing_info->check_after_secs);
$res = $to->get(‘media/upload’, array(“command” => “STATUS”,”media_id” => $sba));
}

//??????????
$res = $to->post(“statuses/update”, array(“status” => $fileText,’media_ids’ => $sba));

??????????
???????????????????????????…

Fatal error: Uncaught exception ‘Abraham\TwitterOAuth\TwitterOAuthException’ with message ‘Operation timed out after 5000 milliseconds with 0 bytes received’

???????????????????????????????
$to->setTimeouts(10, 15);

?????????????

?TwitterOAuth.php on line 366????

??????????????????

//?TwitterOAuth.php???????
/* Remove CACert file when in a PHAR file. */
if (!empty(\Phar::running(false))) {
unset($options[CURLOPT_CAINFO]);
}

?Call to private method Abraham\TwitterOAuth\TwitterOAuth::OAuthRequest() from context????

private method ??????????????
TwitterOAuth.php ? private function oAuthRequest(url,url,method, $parameters) ? private ??????

?”The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.”,”code”:64}

TwitterAPI???????????????v1.1???????????
???TwitterOAuth????????

?Duration too long, maximum:30000, actual:60000
You have to pass the new media_category param in order to use longer videos (> 30 seconds).

30?????????????????????????????????????????

?Segments do not add up to provided total file size.
???????????????????????????????????????????????????????????