Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到PHP-404视频(视频:PUT)YouTube API_Php_Api_Curl_Youtube_Youtube Api - Fatal编程技术网

找不到PHP-404视频(视频:PUT)YouTube API

找不到PHP-404视频(视频:PUT)YouTube API,php,api,curl,youtube,youtube-api,Php,Api,Curl,Youtube,Youtube Api,我正在创建一个小型web应用程序,允许人们在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\u003

我正在创建一个小型web应用程序,允许人们在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));`
有人问了一个类似的问题:然而,答案涉及到他下载并替换视频,这需要额外的配额,而且根本不必这么做


注意在此处完成的API测试中一切正常:

使用
json\u encode
设置请求数据并使用
授权
头设置访问令牌:

<?php

$curl = curl_init();

$access_token = "YOUR_ACCESS_TOKEN";

$data = array(
'kind' => 'youtube#video',
'id' => 'YOUR_VIDEO_ID',
'snippet' => array(
    "title" => "Test title done through php",
    "categoryId" => "1"
)
);
curl_setopt($curl,CURLOPT_URL, "https://www.googleapis.com/youtube/v3/videos?part=snippet");
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','Authorization: Bearer ' . $access_token));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_VERBOSE, true);

$result = curl_exec($curl);

curl_close($curl);

var_dump($result);
?>

太棒了!你知道为什么它对我不起作用吗?