问题
The following code does not work, how can I use it to upload files on YouTube?
$service_url = 'https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet,status';
$c = curl_init($service_url);
$curl_post_data = array(
"Authorization" => $val,
"Content-Length" => '275',
"Content-Type" => 'application/json; charset=UTF-8',
"X-Upload-Content-Length" => '2394849',
"X-Upload-Content-Type" => 'video/mov'
);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_resp = curl_exec($c);
curl_close($c);
echo $curl_resp;
}else {
$authUrl = $client->createAuthUrl();
print "<a href='$authUrl'>upload</a>";
}
?>
please refer to following question which is complete version of this question Q
回答1:
Try creating a installed application as other in Dev Console if you are trying it locally (you seem to do it so with localhost redirect), then try it as a web application when you try on server.
Make sure you set the right credentials each time.
来源:https://stackoverflow.com/questions/17008987/how-to-upload-files-on-youtube-using-resumable-upload-api-v3