Search code examples
javaandroidyoutube-apiyoutube-data-apiandroid-youtube-api

Youtube API Request, Service Error 403


In my application, I am attempting to fetch Channel data, such as total number of video uploads and subscriber count. However, when running my application, I encounter the following error:

E/Service Error:: 403 : The request did not specify any Android package name or signing-certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions.

As far as obtaining OAuth Credentials, I have followed several guides, including the guides provided on the Google Developers webpage:

  1. Navigated to my C:\Program Files\Java\jre1.8.0_101\bin directory and opened this location in a terminal window.
  2. Input the following command keytool -list -v - keystore "C:\Users\[PATH_TO_ANDROIDDEBUGKEY].keystore". Used android as the password.
  3. On the API Console :
    • Created Credentials, and for key restriction, selected Android Apps
    • Copied the SHA-1 fingerprint and pasted into the API Console. Also typed in my applications package name (found in my AndroidManifest.xml file).
  4. Saved settings.

I copied the API key into my application, and always access it statically. ie:

youtube = new YouTube.Builder(...).setYouTubeRequestInitializer(new YouTubeRequestInitializer(Config.YOUTUBE_API_KEY)).setApplicationName("MY_APPLICATION_NAME").build();

YouTube.Channels.List query = youtube.channels().list("statistics");
query.setKey(Config.YOUTUBE_API_KEY);
query.setFields("items(statistics(subscriberCount,videoCount))");
ChannelListResponse response = query.execute();

So I have no idea why I am encountering the error above when I have completed the steps correctly? This issue was previously discussed here, but the answer selected is not what I was expecting, as I would like to have Key Restriction.


Other Steps I Have Taken to Resolve the Service Error

  • Generated my owned signed APK and keystore. I followed the same steps provided above (changing the keystore path) to obtain the SHA-1 fingerprint and pasted into the API Console ---> Did not resolve
  • Created an entirely new API Key and followed the steps provided above ---> Did not resolve
  • Used this terminal command instead to obtain the SHA-1 Fingerprint : keytool -exportcert -alias androiddebugkey -keystore [path-to-debug-or-production-keystore] -list -v ---> Did not resolve
  • Ensured the Youtube Data API v3 is enabled on the API Manager Dashboard ---> Did not resolve

Can anyone please provide an answer as to why I am receiving a Service Error if I have followed the credential steps listed in the guides?


Solution

  • Well, I don't know if this is a bug or not. But according to this thread it might be a bug in the Google System. The only workaround that I see in the internet for this issue is by using a Browser key instead of Android key. If you have time, try also to check this SO question about Restricting usage for an Android key