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

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

问题描述

我在整合youtube v3 API时遇到了困难.我尝试了 Youtube API密钥中提供的所有可能的解决方案.

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

这是我的代码:

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();

根据 Ayman Al-Absi 的回答,我还尝试传递packageName并生成SHA1(ZFzdtB22bpkKGc1kSgi0qxUPSWk =).

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 :

{代码":403,错误":[ { "domain":"usageLimits", "message":"Android包名称和签名证书指纹com.example.somename和ZFzdtB22bpkKGc1kSgi0qxUPSWk =, 与您在API密钥上配置的应用限制不匹配.请用 API控制台以更新您的密钥限制., "reason":"ipRefererBlocked", "extendedHelp":" https://console.developers.google.com/apis/credentials?project = 1234567 " }],"message":"Android包名称和签名证书指纹com.example.somename和 ZFzdtB22bpkKGc1kSgi0qxUPSWk =,与应用程序限制不符 在您的API密钥上配置.请使用API​​控制台更新您的 关键限制."}

{ "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密钥配置:

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

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

推荐答案

好吧,这很老了,但我认为这对我来说很有意义,我认为这可能会对其他人有所帮助.我去了oauth,它似​​乎解决了.

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.

真正的问题是,如果您使用不受限制的密钥(并且可能取消了对api的启用),则将有一个计费帐户关联;的API应该工作.如果它不受限制地运行,那么您在正确的轨道上.

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.

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

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天全站免登陆