Youtube数据API和谷歌云端点

Youtube Data API and Google Cloud Endpoints

本文关键字:云端 端点 谷歌 数据 API Youtube      更新时间:2023-09-26

在我的javascript客户端中,我遇到了谷歌云端点与YouTube数据API v3协同工作的问题。我认为我的问题是围绕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"
}

没有关键我的端点工作,但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密钥删除api.client.setApiKey方法调用。

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

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

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

我对Youtube Data API不是很熟悉。但是我认出你们端点使用的代码和我们提供的代码是一样的。您绝对可以将此代码用于端点API。关于Youtube Data,我建议在这里查看。

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

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将内容发送到你的端点。