Android - Youtube API V3 search not working

蹲街弑〆低调 提交于 2019-12-06 07:55:12

问题


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:

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


回答1:


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"
    }
}


来源:https://stackoverflow.com/questions/55101196/android-youtube-api-v3-search-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!