1

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:

{
    "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:

{
    "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!

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
  • Can you give a bit more code here in what your handler does here? I know it can be done, and I know that using the same key for both your endpoints and youtube is wrong, but without more code it's hard to tell you what needs changing Commented Oct 22, 2015 at 16:43
  • Updated with some code, let me know if that helps... I think I need to specify which API I am setting the key for, but not sure how to do that? Thanks! Commented Oct 23, 2015 at 10:36

2 Answers 2

2

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

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

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

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.

1 Comment

Thanks for the help = the link lead to something that gave me the answer, I'll post it as a new answer in a minute.