Search code examples
google-cloud-vision

Google Vision API returns PERMISSION_DENIED


I'm trying to use the Google Vision API. I'm following getting started guide:

  1. I have enabled the Cloud Vision API
  2. I have enabled billing
  3. I have set up an API key
  4. Made base64-encoded data from my image
  5. Made JSON file with settings:

    {
      "requests":[
        {
          "image":{
            "content":"my base64-encoded data"
          },
          "features":[
            {
              "type":"LABEL_DETECTION",
              "maxResults":5
            }
          ]
        }
      ]
    }
    
  6. Sent request with curl:

    $ curl -v -k -s -H "Content-Type: application/json" https://vision.googleapis.com/v1/images:annotate?key=my_browser_key --data-binary @path_to_file.json
    

After that I got response:

    {
      "error": {
        "code": 403,
        "message": "Requests from referer \u003cempty\u003e are blocked.",
        "status": "PERMISSION_DENIED",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.Help",
            "links": [
              {
                "description": "Google developer console API key",
                "url": "https://console.developers.google.com/project/***********/apiui/credential"
              }
            ]
          }
        ]
      }
    }

\u003cempty\u003e means <empty>

Any ideas? Somebody have the same problem?


Solution

  • Did you specify a list of valid referers in the "Accept requests from these HTTP referrers" box shown on that page? If you did you'll probably have to specify one of those:

    curl --referer https://yourwebsite.com/ ...
    

    Or just disable the referer check if you don't need it.