Listing files over REST using API Key gives 403 - google-drive-api

I am simply trying out curl examples from the GDrive API Explorer, specifically this call:
https://developers.google.com/drive/api/v3/reference/files/list
However when I copy the example and execute it with my API key, I get this error:
curl https://www.googleapis.com/drive/v3/files?key=AIzaSyCQfFNMxHVJRaTvXXXXXXXXXX
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file."
}
}
When I try to get a single file using files/{fileId} with the same API key, it works fine and the file metadata is returned.
What is the deal here? Does listing require special permissions, or does API keys have limitations, or..?

Just a hunch, you are trying a file that is not public, that is why you are receiving 403:insufficientFilePermissions. To access this you must authenticate your request using OAuth 2.0.
You can check the documentation About Authorization:
Your application must use OAuth 2.0 to authorize requests. No other
authorization protocols are supported. If your application uses Google
Sign-In, some aspects of authorization are handled for you.

Related

dailyLimitExceededUnreg error on authenticated download requests for abusive files

I'm getting the following error when trying to download files from my Google Drive folder using JavaScript.
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
I'm using googleapis library, version v3 with OAuth2 authorization.
My function downloads most of the files correctly but throws an error on some specific ones each time I run it.
The library itself prints cannotDownloadAbusiveFile error in the console but the response link shows the error above.
The acknowledgeAbuse flag is set to true. The files that this method refuses to download can't be downloaded from the web-interface either because of the viruses.
I tried changing the Google Drive user in OAuth2 to the creator of the files (it was just someone who has access before), it didn't fix anything.
Daily Limit for Unauthenticated Use Exceeded.
Means there is an issue with your authorization at some point you are sending a request with either a missing access token or an expired one.
As for cannotDownloadAbusiveFile you can set a flag in your request it should be one of the optional parameter's. acknowledgeAbuse='true' this will allow you to download files that Google has denoted as unsafe. If it contains malware though from what i recall only the owner can download that.

Get 403 error message when using Google custom search API

I'm getting this message when using Google custom search API. I got both API key(server and browser) and search ID.
Why it says usageLimits? The constraints is 100 queries per day, but i ran the program way less than 100 times....
Where is going wrong... please help!!
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed."
}
I think your API key or CX parameter could be wrong.
Go to the custom search engine editor and recopy the values.
Make sure you have added some sites to search.
Try the link on the right hand pane to test your custom search engine works.

Google Custom Search Engine Error Code 403 : Access Not Configured

I am trying to use Google Custom Search API
I followed Custom Search doc, i am done with the Control panel stuff and got the Search Engine ID as well, IMplemented API and got the API key from the developer console
Public API Access Key - AIzaSyC0m8w-NEP3yrKolboNbPLbhlhmHJc_cB0
Search Engine ID - 005717290701474541337:1mc_u_r_i94
https://www.googleapis.com/customsearch/v1?&key=AIzaSyC0m8w-NEP3yrKolboNbPLbhlhmHJc_cB0&cx=005717290701474541337:1mc_u_r_i94&q=paris
and after making the above request , i got this result
{
"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-Referer 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-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
}
}
I am not getting the expected results, so please help..
Thanks
Everything seems to be ok, it might be an API key Issue.
Try to create an API key for browser it might work

Can't retrieve objects from Google Cloud Storage by their mediaLink

i wrote a project that work well with upload and download objects to/from Google Cloud Storage. I'm able to retrieve the content, the stream, the metadata, but when i get the 'mediaLink' of an object and paste it to the browser, i got this error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
the format of mediaLink URL is shown here:
https://content.googleapis.com/storage/v1/b/bucketname/o/folder%2Finsidefolder%2Fexample.txt
I'm authenticated in my website by the OAuth 2.0 flow, and all the objects uploaded on GCS are with a custom AccessControlList which i decided to set into "allAuthenticatedUsers" in order to give access only to user that are authenticated with my website.
Could anyone help me to solve this issue? Thank you so much
The media link is not inherently authorized. You need to authorize a download using the media link in the same way you'd authorize any other request: by including an appropriate "Authorization" header.
Without providing read permission to "AllUsers", the media link will not work in a web browser.
Also, "AllAuthenticatedUsers" does not mean users that are authenticated with your website. It means "anybody with any Google account."

Google maps APIs for Business returning error code 403 reason accessNotConfigured

I am using Google Maps APIs for business to get location against Cell IDs and MAC addresses of WiFi access point.
That code was working fine on beta server. Now as I moved to production server, I am getting following response
{ "error": { "errors": [ { "domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project." } ], "code": 403, "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project." } }
In console, Beta server IP was added in allowed IPs. I have added production server IP as well. Still getting above response.
Do I need to generate new key after change in allowed IPs or any other change?
The message is self-explaining activate the API for your project
Go to the console, select the desired project(when you have multiple projects), go to APIs & auth ->API's and activate the service Google Maps Geolocation API