如何使用断点续传API v3在YouTube上上传文件
问题描述:
以下代码不起作用,如何使用它在YouTube上上传文件?
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>";
}
?>
请参考以下问题,该问题是该问题的完整版本 Q
please refer to following question which is complete version of this question Q
答
如果您是在本地尝试,请尝试在Dev Console中创建其他已安装的应用程序(似乎是通过localhost重定向这样做的),然后将其作为尝试在服务器上使用Web应用程序.
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.