Google cloud storage API with Android API key not working (however browser API key works)

帅比萌擦擦* 提交于 2019-12-10 11:05:57

问题


I am trying to access a list of objects from google cloud storage from my android application. The call I am using to access google cloud storage is:

GET https://www.googleapis.com/storage/v1/b/{BUCKET_NAME}/o?key={YOUR_API_KEY}

When I set up a Browser API key with no referrers, I get the JSON results I expect. The files in the bucket are publicly accessible and I am simply trying to read them. However, I would like to use an Android API key so that not anyone can access the files. When I use the Android API key, the result I get is:

{
   "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 have set up the Android API key with the correct package name and fingerprints for both my debug keystore and my release build keystore. My app is on the play store using the release keystore, so the package name is unique and the keystore has been used multiple times to update the app. I get the same error returned for both debug builds and release builds.

I have seen people having this issue before, and everyone tells them to use the browser API key, but I would prefer if any access to the cloud storage was only from my app (to keep potential rates low). Am I overlooking something? Has anyone managed to access the cloud storage api with an Android API key?

来源:https://stackoverflow.com/questions/32595910/google-cloud-storage-api-with-android-api-key-not-working-however-browser-api-k

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!