0
votes

I have a sample code here. It is json

{
  "document":{
    "type":"PLAIN_TEXT",
    "content":"Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Pott$
  },
  "encodingType":"UTF8"
}

I found a tutorial on google's documentation on Natural Language processing on reading from Google Cloud Storage.

curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
     -H "Content-Type: application/json; charset=utf-8" \ --data "{
  'document':{
    'type':'PLAIN_TEXT',
    'gcsContentUri':'gs://reubucket/textData'
  }
}" "https://language.googleapis.com/v1/documents:analyzeEntitySentiment"

And the error that I got is

ERROR: (gcloud.auth) Invalid choice: '*************-_m6csS1Wzlj1pyC_J7vzC0'.
Usage: gcloud auth [optional flags] <group | command>
  group may be           application-default
  command may be         activate-service-account | configure-docker | list |
                         login | revoke

How do I call the command with my API key. I need a way to change the "content" to entries into my CSV file. Thank you. Here is an example of the error that I am receiving please help:

mufaroshumba@reucybertextmining:~/myFolder$ gcloud auth activate-service-account --key-file="/home/mufaroshumba/myFolder/reucybertextmining-74fa66372251.json"
Activated service account credentials for: [starting-*******[CENSORED]@reucybertextmining.iam.gserviceaccount.com]
mufaroshumba@reucybertextmining:~/myFolder$ curl "https://language.googleapis.com/v1/documents:analyzeSentiment?key=${API_KEY}" \ -s -X POST -H "Content-Type: app
lication/json" --data-binary @request.json
{
  "error": {
    "code": 401,
    "message": "Permission to access the GCS address is denied.",
    "status": "UNAUTHENTICATED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "document.gcs_content_uri",
            "description": "Permission to access the GCS address is denied."
          }
        ]
      }
    ]
  }
}
curl: (6) Could not resolve host:  -s
mufaroshumba@reucybertextmining:~/myFolder$

I then used this website trying to get

1
cloud.google.com/natural-language/docs/… I used this website, and uploaded my CSV file to google storage.Mufaro Shumba

1 Answers

1
votes

It looks like your auth is not setup correctly. If you just run this command: gcloud auth application-default print-access-token it should be giving you a token, but it seems like it's not. Please follow the steps here to make sure that this command is working first: https://cloud.google.com/natural-language/docs/quickstart#quickstart-analyze-entities-cli

Then, as long as you have permission to access the gcs bucket, you should be able to get content out of it. Note that the API is expecting to see the actual content in the gcs file, and not a CSV.