Search code examples
androidandroid-studioyoutube-apiyoutube-data-apiandroid-youtube-api

Youtube API Key


When I try to use YouTube API for Search, I get this error:

There was a 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.

In the MainActivity I have this code:

youtube = new YouTube.Builder(new NetHttpTransport(), JSON_FACTORY, new HttpRequestInitializer() {
                    @Override
                    public void initialize(HttpRequest httpRequest) throws IOException {

                    }
                }).setYouTubeRequestInitializer(new YouTubeRequestInitializer(apiKey)).setApplicationName("Some Name").build();

In the cloud console I have an ApiKey for Android, with the package name set and the SHA-1 number obtained with keytool command.


Solution

  • After lot of trial and error, the thing which finally worked for me was changing API KEY restriction to None instead of Android from API Manager console and just save. enter image description here

    After doing the above step I am able to make search API call from my Android device using my API KEY.