Android - Youtube API V3 搜索不工作 [英] Android - Youtube API V3 search not working

查看:21
本文介绍了Android - Youtube API V3 搜索不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难集成 youtube v3 API.我尝试了

我为调试和生产环境添加了 SHA-1 指纹.

解决方案

好吧,这已经很老了,但我为我的情况想出了这个,我认为它可能会帮助其他人.我去了oauth,它似​​乎解决了.

真正的问题是,如果您使用不受限制的密钥 [也许,取决于启用的 api] 有一个计费帐户链接;api 应该可以工作.如果它不受限制地工作,那么您就在正确的轨道上.

一旦您将其限制为 android,它将再次使用该密钥失败,直到您签署您的应用程序.我发现的最简单的方法是在 gradle 文件中为 android 下的变体使用签名配置.

signingConfigs {调试{storeFile 文件(/users/xxxxxxxxxx/Android/keystores/google_demos/debugandroid.jks")商店密码xxxxxxxxxx"keyAlias "com.example.xxxxxxxxxx"密钥密码xxxxxxxx"}}

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.

解决方案

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

这篇关于Android - Youtube API V3 搜索不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆