Youtube 数据 API 和 Google 云端点
Youtube Data API and Google Cloud Endpoints
我在让 Google 云端点与我的 javascript 客户端中的 YouTube 数据 API v3 协同工作时遇到问题。我认为我的问题是关于为我的端点 API 和 YouTube api 设置密钥的 gapi.client.setApiKey()
方法。当我设置密钥时,YouTube 工作但我的端点不工作,我使用我的端点 API:
看到以下错误
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. The API () is not enabled for your project. Please use the Google
Developers Console to update your configuration.",
"extendedHelp": "https://console.developers.google.com"
}
没有密钥,我的端点可以工作,但 youtube 搜索不起作用,我使用搜索功能收到此消息:
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
加载 API 的代码总结如下,但基本上我遵循了端点 python/javascript 教程和 youtube 数据 API 教程!
init = function(apiRoot) {
var apisToLoad;
var callback = function(){
if(--apisToLoad == 0){
enableButtons();
}
}
apisToLoad = 2; // must match number of calls to gapi.client.load()
gapi.client.load('myAPIName', 'v1', callback, apiRoot);
gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
};
// Called automatically when YouTube API interface is loaded (see line 9).
function onYouTubeApiLoad() {
//sets the api key
gapi.client.setApiKey('APIKeyForYouTubeFromDevConsole');
}
我对 Youtube 数据不是很熟悉 API。但我认为您用于端点的代码是我们提供的代码。您绝对可以将此代码用于端点 API。对于 Youtube 数据,我建议 looking here.
看起来您需要的代码是这样的:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.services.youtube.YouTube;
public class myClass {
/**
* Define a global instance of a Youtube object, which will be used
* to make YouTube Data API requests.
*/
private static YouTube youtube;
public static void main(String[] args) {
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "invideoprogramming");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
.setApplicationName([YOUR APP])
.build();
}
从那里您应该能够使用 youtube 对象进行调用,并使用 gapi 将内容发送到您的端点。
要仅验证带有 API 键的 youtube API 请求,请删除 api.client.setApiKey
方法调用。
在调用 YouTube 数据时 API 向 API 请求添加关键参数:
var request = gapi.client.youtube.search.list({
part: 'snippet',
type: 'video',
maxResults: 12,
q: searchValue,
key: 'YourAPIKeyGoesHere'
});
这意味着只有这些 API 调用被授权,端点调用未被授权。
我在让 Google 云端点与我的 javascript 客户端中的 YouTube 数据 API v3 协同工作时遇到问题。我认为我的问题是关于为我的端点 API 和 YouTube api 设置密钥的 gapi.client.setApiKey()
方法。当我设置密钥时,YouTube 工作但我的端点不工作,我使用我的端点 API:
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. The API () is not enabled for your project. Please use the Google
Developers Console to update your configuration.",
"extendedHelp": "https://console.developers.google.com"
}
没有密钥,我的端点可以工作,但 youtube 搜索不起作用,我使用搜索功能收到此消息:
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
加载 API 的代码总结如下,但基本上我遵循了端点 python/javascript 教程和 youtube 数据 API 教程!
init = function(apiRoot) {
var apisToLoad;
var callback = function(){
if(--apisToLoad == 0){
enableButtons();
}
}
apisToLoad = 2; // must match number of calls to gapi.client.load()
gapi.client.load('myAPIName', 'v1', callback, apiRoot);
gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
};
// Called automatically when YouTube API interface is loaded (see line 9).
function onYouTubeApiLoad() {
//sets the api key
gapi.client.setApiKey('APIKeyForYouTubeFromDevConsole');
}
我对 Youtube 数据不是很熟悉 API。但我认为您用于端点的代码是我们提供的代码。您绝对可以将此代码用于端点 API。对于 Youtube 数据,我建议 looking here.
看起来您需要的代码是这样的:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.services.youtube.YouTube;
public class myClass {
/**
* Define a global instance of a Youtube object, which will be used
* to make YouTube Data API requests.
*/
private static YouTube youtube;
public static void main(String[] args) {
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "invideoprogramming");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
.setApplicationName([YOUR APP])
.build();
}
从那里您应该能够使用 youtube 对象进行调用,并使用 gapi 将内容发送到您的端点。
要仅验证带有 API 键的 youtube API 请求,请删除 api.client.setApiKey
方法调用。
在调用 YouTube 数据时 API 向 API 请求添加关键参数:
var request = gapi.client.youtube.search.list({
part: 'snippet',
type: 'video',
maxResults: 12,
q: searchValue,
key: 'YourAPIKeyGoesHere'
});
这意味着只有这些 API 调用被授权,端点调用未被授权。