Reputation: 1255
The google api project for my app contains a simple android key with two applications allowed. one is the com.examples.youtubeapidemo, the other is my app. If I take the com.examples.youtubeapidemo in and out of the key it fails as expected. The other app always returns this response:
11-06 08:06:52.321 32579-528/com.wfs.android.youtubesearchtest E/com.wfs.android.youtubesearchtest﹕ 403 Forbidden { "code" : 403, "errors" : [ { "domain" : "usageLimits", "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project.", "reason" : "accessNotConfigured" } ], "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project." }
my code is this: [in an async task]
{
YouTube.Builder builder = new YouTube.Builder(
new NetHttpTransport(),
new JacksonFactory(),
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request)
throws IOException {
}
})
.setApplicationName((String.valueOf(R.string.app_name)));
return builder.build();
}
and this:
{
// ...
YouTube youTube = createYouTubeService();
YouTube.Search.List search = null;
try {
search = youTube.search().list("id,snippet");
} catch (IOException e) {
Log.e(TAG, e.getMessage());
return null;
}
search.setKey(Developerkey.DEVELOPER_KEY);
search.setQ(q[0]);
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED);
SearchListResponse searchListResponse = null;
try {
searchListResponse = search.execute();
}
The exception is thrown in searchListResponse = search.execute();
I have tested the key, is there anything I may have missed in the code?
I also tested with a browser key and the com.examples.youtubeapidemo works with either one. My app still has the same issue; So all the posts about using a browser key instead did not work for me.
Upvotes: 2
Views: 820
Reputation: 1255
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"
}
}
Upvotes: 2