Reputation: 3463
Using Android Studio, I am creating an app that lists YouTube videos based on some criteria. I am using the Search list method. In the app I make a call to the YouTube API and parse the results.
This app works fine using a 'Server' key when on my home Wifi. However, when switching to an 'Android' key, the app no longer works. The calls to the API are no longer returning the expected data, and are giving a java.io.FileNotFoundException: https://www.googleapis.com/youtube/v3/search...
error.
I am setting up the YouTube API key at the Google Developers Console. I create a 'Public API access' key, using the SHA1 output from the command keytool -list -v -keystore .android/debug.keystore
, and then appending a semicolon and package name 'com.mysite.projectname' (as is stated in the instructions).
I am having a hard time figuring out the issue. It seems that the API key is set up correctly and should be working (at least for development).
--Adding edit for answer below
I use the class below to store my API key. I access the key using DeveloperKey.DEVELOPER_KEY
in other classes. As mentioned, this works when I have a 'Server' key instead of and 'Android' key.
package com.mysite.projectname;
public class DeveloperKey {
public static final String DEVELOPER_KEY = "MyAPIKey";
}
Calling the API like:
https://www.googleapis.com/youtube/v3/search?part=snippet........&key=MyAPIKey
Upvotes: 2
Views: 668
Reputation: 1578
I would post this as a comment but apparently I can't, so here goes nothing. How are you implementing the key in your app? The easiest way is to chuck it into strings.xml and call it using something like this:
setContentView(R.layout.activity_youtube_player);
//initialize
YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
youTubePlayerView.initialize(getString(R.string.api_youtube), this);
and strings.xml looking something like
<string name="api_youtube">MYFANCYKEYHERE</string>
Can you post snippets of your implementation?
EDIT
It sounds like you're grabbing the SHA1 key correctly (you can reference against this guy if you want to check if you're doing it right). To elaborate on my comment below, I'm not sure if you can actually grab youtube videos from that link from an Android platform. The Youtube API lets you do that very easily, though you have to remember to put in the appropriate permission <uses-permission android:name="android.permission.INTERNET" />
in your manifest first. I've given a link below that's a tutorial on how to do it the Google Approved (TM) way, and if you're bored and want to pull it the rtsp way, this fella has instructions how. (But I wouldn't recommend it because the quality's crap).
Upvotes: 1