Youtube Data API和Google Cloud Endpoints

时间:2022-08-22 11:19:50

I'm having issues getting Google cloud endpoints working in tandem with the YouTube data API v3 in my javascript client. I think my issue is around the gapi.client.setApiKey() method setting the key for both my endpoints API and the YouTube api. When I do set the key YouTube works but my endpoints do not and I see the following error using my endpoints API:

我在使用javascript客户端中的Google数据API v3与Google云端点协同工作时遇到了问题。我认为我的问题是使用gapi.client.setApiKey()方法设置我的端点API和YouTube api的密钥。当我设置密钥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"
}

Without the key my endpoints work but youtube search does not and I get this message using the search feature:

如果没有密钥,我的端点可以正常工作,但youtube搜索没有,我使用搜索功能获取此消息:

{
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
}

The code that loads the API is summarised below but essentially I have followed the endpoints python/javascript tutorial and the youtube data API tutorials!

加载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');
}

2 个解决方案

#1


2  

To verify only the youtube API requests with the API key remove the api.client.setApiKey method call.

要仅使用API​​密钥验证youtube API请求,请删除api.client.setApiKey方法调用。

In calls to the YouTube data API add a key parameter to the API request:

在调用YouTube数据API时,为API请求添加一个关键参数:

var request = gapi.client.youtube.search.list({
    part: 'snippet',
    type: 'video',
    maxResults: 12,
    q: searchValue,
    key: 'YourAPIKeyGoesHere'
});

This means only these API calls are authorised and not the endpoints calls.

这意味着只有这些API调用被授权,而不是端点调用。

#2


1  

I'm not extremely familiar with the Youtube Data API. But I recognize the code you used for your Endpoints as the code that we provide. You can definitely use this code for the Endpoints API. For the Youtube Data one, I suggest looking here.

我对Youtube Data API并不是很熟悉。但我将您用于端点的代码识别为我们提供的代码。您绝对可以将此代码用于Endpoints API。对于Youtube数据,我建议看这里。

Looks like the code you need would be something like this :

看起来你需要的代码是这样的:

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();
        }

From there you should be able to use the youtube object to make your calls, and the gapi to send stuff to your endpoint.

从那里你应该能够使用youtube对象进行调用,并使用gapi将东西发送到你的终端。

#1


2  

To verify only the youtube API requests with the API key remove the api.client.setApiKey method call.

要仅使用API​​密钥验证youtube API请求,请删除api.client.setApiKey方法调用。

In calls to the YouTube data API add a key parameter to the API request:

在调用YouTube数据API时,为API请求添加一个关键参数:

var request = gapi.client.youtube.search.list({
    part: 'snippet',
    type: 'video',
    maxResults: 12,
    q: searchValue,
    key: 'YourAPIKeyGoesHere'
});

This means only these API calls are authorised and not the endpoints calls.

这意味着只有这些API调用被授权,而不是端点调用。

#2


1  

I'm not extremely familiar with the Youtube Data API. But I recognize the code you used for your Endpoints as the code that we provide. You can definitely use this code for the Endpoints API. For the Youtube Data one, I suggest looking here.

我对Youtube Data API并不是很熟悉。但我将您用于端点的代码识别为我们提供的代码。您绝对可以将此代码用于Endpoints API。对于Youtube数据,我建议看这里。

Looks like the code you need would be something like this :

看起来你需要的代码是这样的:

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();
        }

From there you should be able to use the youtube object to make your calls, and the gapi to send stuff to your endpoint.

从那里你应该能够使用youtube对象进行调用,并使用gapi将东西发送到你的终端。