【发布时间】:2017-09-13 01:40:59
【问题描述】:
我正在创建一个小型网络应用程序,允许人们在 YouTube 之外更新他们的视频。我目前正在为自己测试,我遇到了
{ "error": { "errors": [ { "domain": "youtube.video", "reason": "videoNotFound", "message": "The video that you are trying to update cannot be found. Check the value of the \u003ccode\u003eid\u003c/code\u003e field in the request body to ensure that it is correct.", "locationType": "other", "location": "body.id" } ], "code": 404, "message": "The video that you are trying to update cannot be found. Check the value of the \u003ccode\u003eid\u003c/code\u003e field in the request body to ensure that it is correct." } }
我确定的事情:
- 我有正确的授权码
- 我拥有此授权码所指的正确渠道。
- 我的视频 ID 正确。
我在 PHP 中使用 cURL 发送PUT 请求,如下所示:
$curl = curl_init($url . "https://www.googleapis.com/youtube/v3/videos?part=snippet&access_token=".$token)
$data = array(
'kind' => 'youtube#video',
'id' => 'theCorrectIdIsHere',
'snippet' => array(
"title" => "Test title done through php",
"categoryId" => "1"
),
);`
那么当我使用以下命令执行此操作时:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:
application/json'));
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));`
有人问了一个类似的问题:Update title and description using YouTube v3 API?,但是,答案涉及他下载和替换视频,这需要额外的配额并且根本不应该这样做
注意在这里完成的 API 测试一切正常:https://developers.google.com/youtube/v3/docs/videos/update
【问题讨论】:
标签: php api curl youtube youtube-api