YouTube API v3 - keyInvalid Error 400 - PHP

问题描述 投票:1回答:2

如果我尝试获取频道的所有视频,我总是会收到此错误。

{ "error": { "errors": [ { "domain": "usageLimits", "reason": "keyInvalid", "message": "Bad Request" } ], "code": 400, "message": "Bad Request" } }

我的代码如下

$api_key = "AIzaSyD...nR8";
stream_context_set_default(['http' => ['ignore_errors' => true]]);
$source_videos = file_get_contents("https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId={UCuB3qjWes1E8t4yUmbP360Q}&maxResults=1&key={".$api_key."}");

echo $api_key;
echo $source_videos;

我在https://console.developers.google.com/apis/dashboard上创建了一个项目并添加了,激活了“YouTube Data API v3”,用“Webserver(例如Node.js,Tomcat)”作为平台创建了凭证,最后在我的php文档中复制了密钥。我不知道为什么我不能让它工作。我很感激帮助。 :)

编辑:

使用Webbrowser(JavaScript)作为平台,它应该工作。

php youtube-data-api
2个回答
0
投票
try this code
    $API_key    = 'AIzaSyCTPwxSs1id2kdv_fupUfbYkfa6Fucp_6A';
    $channelID  = 'UCTCU28hEulL2jkafQ21uuWA';
    $maxResults = 10;

    $videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));

注意:你需要一个虚拟服务器来运行php(wamp / mamp / xampp)


0
投票

使用Webbrowser(JavaScript)作为平台,它应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.