Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 871
Roaders Avatar asked Feb 24 '16 10:02

Roaders


People also ask

What does API key not valid mean?

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.

How do I enable vision API in Google cloud?

Again, use the hamburger menu to get the nav bar, and select the the API manager, and "Dashboard" from the sub-menu. Click "Enable API" at the top. On the next screen, find the Cloud Vision API, and select it. Then click "Enable".


2 Answers

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"

like image 96
Tim Swast Avatar answered Oct 17 '22 08:10

Tim Swast


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.

like image 6
demongolem Avatar answered Oct 17 '22 07:10

demongolem