从 Youtube API 的文档中复制的示例不起作用
Copied example from documentation of Youtube API not working
我正在尝试使用 Youtube API 搜索包含一些单词的视频,并且我有 运行 我在这个交互式应用程序 https://developers.google.com/youtube/v3/docs/search/list?apix=true&apix_params=%7B%22part%22%3A%5B%22snippet%22%5D%2C%22q%22%3A%22ay%20vamos%22%7D 上的示例。我已经复制了该页面上的源代码并删除了授权,因为我不需要它并填写了凭据。这是我不断收到的错误 Uncaught TypeError: Cannot read property 'youtube' of undefined
<body>
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for youtube.search.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function loadClient() {
gapi.client.setApiKey("-------------------");
return gapi.client
.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(
function () {
return gapi.client.youtube.search
.list({
part: ["snippet"],
q: "ay vamos",
})
.then(
function (response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function (err) {
console.error("Execute error", err);
}
);
},
function (err) {
console.error("Error loading GAPI client for API", err);
}
);
}
// Make sure the client is loaded and sign-in is complete before calling this method.
</script>
<button onclick="loadClient()">execute</button>
</body>
“无法读取未定义的 属性 'youtube'”提示 gapi.client
未正确定义。我自己 运行 你的代码并打印 gapi.client
到控制台输出 null
.
此外,我找不到任何调用您的 loadClient()
函数的东西,看起来它负责实际加载 youtube 客户端?那可能是一个单独的问题。
我正在尝试使用 Youtube API 搜索包含一些单词的视频,并且我有 运行 我在这个交互式应用程序 https://developers.google.com/youtube/v3/docs/search/list?apix=true&apix_params=%7B%22part%22%3A%5B%22snippet%22%5D%2C%22q%22%3A%22ay%20vamos%22%7D 上的示例。我已经复制了该页面上的源代码并删除了授权,因为我不需要它并填写了凭据。这是我不断收到的错误 Uncaught TypeError: Cannot read property 'youtube' of undefined
<body>
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for youtube.search.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function loadClient() {
gapi.client.setApiKey("-------------------");
return gapi.client
.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(
function () {
return gapi.client.youtube.search
.list({
part: ["snippet"],
q: "ay vamos",
})
.then(
function (response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function (err) {
console.error("Execute error", err);
}
);
},
function (err) {
console.error("Error loading GAPI client for API", err);
}
);
}
// Make sure the client is loaded and sign-in is complete before calling this method.
</script>
<button onclick="loadClient()">execute</button>
</body>
“无法读取未定义的 属性 'youtube'”提示 gapi.client
未正确定义。我自己 运行 你的代码并打印 gapi.client
到控制台输出 null
.
此外,我找不到任何调用您的 loadClient()
函数的东西,看起来它负责实际加载 youtube 客户端?那可能是一个单独的问题。