3

I'm having tough time integrating youtube v3 API. I tried all the possible solutions given in Youtube API Key.

Here is my code:

YouTube.Search.List query; 
query = youTube.search().list("id, snippet");
query.setKey(YOUR_API_KEY); 
query.setMaxResults(5L); 
query.setChannelId(channelId); 
query.setOrder("date"); 
SearchListResponse response = query.execute(); 
List<SearchResult> results = response.getItems();

As per Ayman Al-Absi's answer, I also tried passing packageName and and generated SHA1 (ZFzdtB22bpkKGc1kSgi0qxUPSWk=).

request.getHeaders().set("X-Android-Package", packageName);
request.getHeaders().set("X-Android-Cert",signature);

But when I did that I got error :

{ "code": 403, "errors": [ { "domain": "usageLimits", "message": "The Android package name and signing-certificate fingerprint, com.example.somename and ZFzdtB22bpkKGc1kSgi0qxUPSWk=, do not match the app restrictions configured on your API key. Please use the API Console to update your key restrictions.", "reason": "ipRefererBlocked", "extendedHelp": "https://console.developers.google.com/apis/credentials?project=1234567" } ], "message": "The Android package name and signing-certificate fingerprint, com.example.somename and ZFzdtB22bpkKGc1kSgi0qxUPSWk=, do not match the app restrictions configured on your API key. Please use the API Console to update your key restrictions." }

API key configurations:

enter image description here

I have added SHA-1 fingerprints for both debug and prod environments.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Audumbar
  • 404
  • 5
  • 16

1 Answers1

0

Ok this is old but I figured this out for my case and I thought it might help others. I went to oauth and it seemed to resolve.

the real issue is that if you use an unrestricted key [and maybe, depepending on the api enabled] have a billing account linked; the api should work. If it works unrestricted, you are on the right track.

Once you restrict it to android it will fail again with that key until you sign your app. The easiest way i found was the use a signing config for the variants under android in the gradle file.

signingConfigs {
    debug {
        storeFile file("/users/xxxxxxxxxx/Android/keystores/google_demos/debugandroid.jks")
        storePassword "xxxxxxxxxx"
        keyAlias "com.example.xxxxxxxxxx"
        keyPassword "xxxxxxxx"
    }
}
  • I know we can also achieve using oauth2 client , but in my case I need to use API-key and as per google documentation it should be possible. – Audumbar Mar 16 '19 at 04:56
  • I remember going round and round trying to get this to work just for search and having a hard time. Then in my app I needed to post videos to the user account anyway; implemented oauth instead and it worked, There are some old posts on SO that suggest using a web key instead and I think I got that working at one point. But I honestly don't know if that works any more. I learned with the sample app that used a key and it does not work for me right now. – keepTrackOfYourStack Mar 16 '19 at 15:27
  • Yes. I also tried using web key. That also not working. Thanks. – Audumbar Mar 16 '19 at 15:58