Request search results for YouTube Data API in Volley.

Asked 1 years ago, Updated 1 years ago, 115 views

When I requested at the following URL, the following error occurred:

Error Contents:

01-22 22:24:43.326 23433-23461/com.hoge.piyo.buzz E/Volley ﹕ 
    [2094] BasicNetwork.performRequest: Unexpected response code 400 for 
        https://www.googleapis.com/youtube/v3/search?q=%E3%81%BB%E3%81%92&part=id,snippet&maxResults=20&order=viewCount&type=video&videoDefinition=high&publishedAfter=2015-01-21T10:24:42Z&key=API_KEY

After retrieving and executing APIKey from the browser, I was able to receive a normal result.

There should be no problem retrieving APIKey.

Sorry, I forgot to write APIKey as a constant in the above request. I'm sorry, but when I fixed it and executed it, I got the following error:

Error Contents

01-23 19:39:27.832 16150-16194/com.hoge.piyo.buzzE/Volley [[4276]BasicNetwork.performRequest:Unexpected response code 403 for https://www.googleapis.com/youtube/v3/search?q=hoge&part=id,snippet&maxResults=20&order=viewCount&type=video&videoDefinition=high&publishedAfter=2015-01-22T07:39:27Z&key=API_KEY

logging output
com.android.volley.AuthFailureError

Also, is the following instruction to display the server response?
Log.e("tag", new String(error.networkResponse.data,error));
If you write this down, you cannot run it as String(byte[], com.volley.VolleyError).

When I displayed the response in the Log, I got the following results:
Response log output:

"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Refer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration,."
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Refer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
}
}
com.android.volley.AuthFailureError
        at com.android.volley.toolbox.BasicNetwork.performRequest (BasicNetwork.java:159)
        atcom.android.volley.NetworkDispatcher.run (NetworkDispatcher.java:112)

I also thought that APIKey was wrong, so I reissued APIKey and checked if the package was wrong, but somehow it didn't work.

android youtube-data-api android-volley

2022-09-30 20:32

1 Answers

"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Refer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."

This error message was displayed when the 許可Allowed IP Address 」 configured when creating the API KEY was incorrectly configured (although it may appear in other cases).
As a trial, you may want to try 0.0.0/0 in the API and Authentication > Credentials screen of the Developers Console. (When I tried it, it took me a few minutes to reflect it, so if it didn't work, I might wait a little while.)

Also, I tried using Android to see if I needed an ApiKey created for Android, and I was able to confirm that the key for the server worked fine (although, if you want to distribute the app to the public, you should use the key set for Android).Otherwise, a malicious third party may be able to execute a large number of API requests using your ApiKey.)

postscript;
Fingerprint of signature key is required to issue ApiKey for Android.I found the following helpful.
How to create a signature keystore:
http://techbooster.org/android/environment/1445/
How to get a fingerprint of a signature key:
http://www.ipentec.com/document/document.aspx?page=android-get-certificate-fingerprints


2022-09-30 20:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.