API Key not valid error when trying to access Google cloud vision api
Asked Answered
F

4

16

I am trying to test out the vision API and have uploaded some images to Google cloud storage and have created a browser app that requests the cloud api to process them.

I have a client_id file that I downloaded from the Google developers console. This has a client_id value that I am using as my api key.

I make a request to

https://content-vision.googleapis.com/v1/images:annotate?alt=json&key=414712345643-cln7htsuv78jr9i64v8v7g6cnhm3ccff.apps.googleusercontent.com

(api key altered)

and post the request:

{
  "requests": [
    {
      "image": {
        "source": {
          "gcsImageUri": "https:\/\/console.cloud.google.com\/m\/cloudstorage\/b\/estoril_test\/o\/AI4C3160.JPG"
        }
      },
      "features": [
        {
          "type": "LABEL_DETECTION",
          "maxResults": 1
        }
      ]
    }
  ]
}

but I get an error:

{
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developer console API key",
            "url": "https://console.developers.google.com/project/414754136843/apiui/credential"
          }
        ]
      }
    ]
  }
}

I have authorized that api key for the cloud vision api so what am I doing wrong? I did try the curl example in the demo but I keep getting

Protocol https not supported or disabled in libcurl

I tried adding double quotes as some research suggested I should but still no luck.

Fanning answered 24/2, 2016 at 10:32 Comment(0)
P
9

For the "API key not valid" issue, it appears that you are using a Server key, but you need to use a browser key. The Vision API Getting Started page has detailed screenshots, as well as a curl example.

The second issue you are likely to encounter is that the gcsImageUri is the incorrect format. According to the Vision API reference docs the image URI must be in the form "gs://bucket_name/object_name", so in your case: something like: "gs://storil_test/AI4C3160.JPG"

Parish answered 24/2, 2016 at 17:45 Comment(2)
Thanks for this answer. It did help but I still have issues. If I use a browser key then I cannot use it for authenticating a user using OAuth and if I cannot do that I can't access the images in cloud storage as you need an authenticated user to do that. (even though the images are shared publicly) A browser key only seems to work for uploading images with the request.Fanning
My permissions for my cloud bucket weren't open to all actually. I updated it and I'm getting a different error now! Thanks for the help.Fanning
D
6

Problem is resolved.

After generating credentials, Click on 'Create Credentials' Drop down and choose - 'API Key'; the generated API Key will be used..

Dorladorlisa answered 26/7, 2017 at 10:19 Comment(0)
T
6

Another problem that can be encountered with a KEY not working is that a particular service has not been added to the project you are trying to work with. That will give this same response.

Tuberculin answered 1/9, 2017 at 15:12 Comment(1)
This was it for me, pretty non obvious when first starting out that you have to enable each service you want to use the key forAchlorhydria
H
3

key=414712345643-cln7htsuv78jr9i64v8v7g6cnhm3ccff.apps.googleusercontent.com

This is "ID client Oauth" key.

sAjnhsejklfynGiuhYGBYUGDYGziodzdCfhAO7qPY

This is an exemple of valid API KEY

To create API KEY follow this link : https://support.google.com/cloud/answer/6158862?hl=en

Hollands answered 23/5, 2017 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.