12

I was trying to run the sample app, found here Github Sample, I have created a certificate and created a API Key and applied as instructed. But when I upload the Image I am getting this Exception. I dont know where I have made a mistake. Have I missed anything?

failed to make API request because {
    "code": 403,
    "errors": [{
        "domain": "global",
        "message": "Requests from this Android client application <empty> are blocked.",
        "reason": "forbidden"
    }],
    "message": "Requests from this Android client application <empty> are blocked.",
    "status": "PERMISSION_DENIED"
}
Kara
  • 6,115
  • 16
  • 50
  • 57
Amalan Dhananjayan
  • 2,277
  • 1
  • 34
  • 47
  • 2
    Any luck? I am kind of facing the same problem! – stack_ved Feb 22 '16 at 07:41
  • 2
    I am also facing the same problem. – KnowIT Feb 22 '16 at 14:02
  • 1
    @amalan-dhananjayan Any chance you have set the bundle identifier in the API key? I'm guessing this might be the same issue we are seeing for the iOS samples. https://github.com/GoogleCloudPlatform/cloud-vision/issues/16 I will see if maybe there's an Android-specific set of client libraries we should be using instead of the Java ones. – Tim Swast Feb 22 '16 at 19:42
  • Yes i have set bundle specifier in my API key, I am not supposed to? – stack_ved Feb 23 '16 at 03:34
  • @TimSwast Yes. I have set the bunddle name/Identifier and the SHA-1 key to create the API Key. I tried with the sample app too, with my own SHA-1 key. It is also giving the same issue – Amalan Dhananjayan Feb 23 '16 at 05:56
  • 1
    It is working for me. I am creating a Browser Key instead of Android Key under API Manager - Credentials while creating API KEY. For some strange reason, it is working – stack_ved Feb 23 '16 at 08:09
  • @TimSwast as stack_ved says the API is working with Browser key. But it is not the proper way I think hope you can fix this issue from your side in a proper way. – Amalan Dhananjayan Feb 23 '16 at 08:23
  • In fact in the link @TimSwast has pasted, i found this work around – stack_ved Feb 23 '16 at 10:57

6 Answers6

9

I suspect that you are creating an Android API key, restricted to your app, with your sha1 fingerprint registered.

This is great! Unfortunately, the non-android-specific Google API java client library doesn't yet fully support API requests for android api keys, like the android-specific one does. This means that API requests aren't including some headers that authenticate the key/app to the API endpoint, which causes that error (note the client application <empty> in the error message - the <empty> would be your package name, if the request was formed as expected).

I'm still looking for what to do about that - will update if / when I find one.

jerjou
  • 1,376
  • 1
  • 10
  • 10
5

I had the same problem. but I solve this.

If you add Browser API Key, your code works well.

NARA YOON
  • 74
  • 1
0

What all did you change in the android project? Make sure that you enable the cloud vision API and enable billing. All I had to do was add my API key in the MainActivity using the same sample from Github.

Take a look at my screenshot

Derivative
  • 267
  • 1
  • 3
  • 11
  • mind sharing what you added as the application package. I am facing the same issue, billing is enabled, but every request fails – Prathamesh Shetye Feb 23 '16 at 02:00
  • sample.google.com.cloudvision is what the sample came with I did not refactor the package name to my own. Hope this helps. – Derivative Feb 23 '16 at 03:02
  • Could you please help us solve this. I guess it should have something to do with enabling billing. I have created an API key and assigned it to the variable CLOUD_VISION_API_KEY. Have Enabled billing and cloud api for my project as well – stack_ved Feb 23 '16 at 03:34
  • Are you using the Github sample? If not, check your permissions in your Android Manifest. They should be: – Derivative Feb 23 '16 at 04:59
0

some problem here, and i fix it!!!!!

just put Server Key!!

enter image description here

hope its help someone

Omri Lugasi
  • 337
  • 3
  • 16
0

I believe using the browser key would solve your problem. But the actual solution to this is using an OAuth Key. Like an Android App should do.

  1. To do so go to the credentials section from the side menu in Cloud Developer Console.
  2. Click on credentials drop down menu and select OAuth Client ID.
  3. Select Application Type as Android.
  4. Add a suitable name like Android client for Cloud Vision API
  5. Enter your SHA1 fingerprint in the desired format. Using the mentioned command on screen.
  6. Enter the package name for your app, can be located in the defaultConfig block of your gradle.
  7. Click on create.

This is an excerpt form the full tutorial here.

KnowIT
  • 2,392
  • 1
  • 18
  • 16
0

You may have also limited your API Key to only allow requests from Android apps. Changing it to None, it will accept all requests, however, this also means less security.

Unterbelichtet
  • 628
  • 2
  • 7
  • 18