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