我试图使用youtube数据API从youtube获取视频数据,但我得到了403个禁止的错误,如下所示
{"error":{"errors":[{"domain":"global","reason":"forbidden","message":"Forbidden"}],"code":403,"message":"Forbidden"}}我想要的是:
var apiKey = "xxxxxxxxxxxxxxxxxxxxx";
var videoId = "s7wmiS2mSXY";
var gUrl = "https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&key=" + apiKey + "&part=snippet,statistics,contentDetails";
$http({
method: 'GET',
url: gUrl
}).then(function successCallback(response) {
console.log('sucess call.', response);
}, function errorCallback(err) {
console.log('Error while saving this Video Id details in videoId.', err);
});当我复制整个url https://www.googleapis.com/youtube/v3/videos?id=s7wmiS2mSXY&key=XXXXmyApiKeyXXXXX&part=snippet,statistics,contentDetails并在一个新的选项卡中尝试时,我在浏览器中获取json对象,但是当我使用$http.get在本地主机上尝试它时,我得到了403禁止的错误。
提前谢谢。
发布于 2017-07-17 10:42:22
很可能你的问题是你的钥匙,如果你是一个403错误。我会回去看看它是对的。我尝试用jquery重新创建您的问题,但它似乎运行得很好。我的代码是:
var apiKey = "xxxxxxx my_key xxxxxx";
var videoId = "s7wmiS2mSXY";
var gUrl = "https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&key=" + apiKey + "&part=snippet,statistics,contentDetails";
$.get(gUrl, function (data) {
console.log(data);
});https://stackoverflow.com/questions/45141465
复制相似问题