如何使用Google Cloud Storage中的Google Natural Language处理?

时间:2018-07-09 17:48:12

标签: csv google-app-engine google-cloud-platform google-natural-language

我在这里有示例代码。是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"
}

我从Google云端存储中读取了有关Google自然语言处理文档的教程。

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"

我得到的错误是

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

如何使用API​​密钥调用该命令。 我需要一种将“内容”更改为CSV文件中条目的方法。 谢谢。 这是我收到的错误示例,请帮助:

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$

然后我使用此网站尝试获取

1 个答案:

答案 0 :(得分:1)

似乎您的身份验证未正确设置。如果只运行以下命令: gcloud auth应用程序-默认打印访问令牌 它应该给您一个令牌,但事实并非如此。请按照此处的步骤操作,以确保首先运行此命令: https://cloud.google.com/natural-language/docs/quickstart#quickstart-analyze-entities-cli

然后,只要您有权访问gcs存储桶,就应该能够从其中获取内容。请注意,API希望在gcs文件中看到实际内容,而不是CSV。