问题解决!
我意识到我没有通过服务帐户的密钥文件的位置。像这样:
gcloud auth activate-service-account --key-file=service-account-key-file
我通过下载来自信任区的键,然后重新上传它到谷歌云Shell命令行(它有一个名为“猎户座”一个漂亮的代码编辑器,可以查看和编辑每一个这样做上传的文件)。
我然后从步骤3开始here
接着我修改了代码在步骤4到API发送到一个对象,在谷歌云存储桶,像这样:
curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer xxxxxxxxxxxauth-tokenxxxxxxxxxxxxxx" --data-binary @requestb.json https://language.googleapis.com/v1beta1/documents:analyzeEntities?key=${NL_API_KEY}
上面'@ requestb.json'是我上传到Google Cloud Shell的另一个文本文件,其中包含以下json信息:
{
"document":{
"type":"PLAIN_TEXT",
"gcsContentUri": "gs://<bucket-name>/<object-name>"
}
}
它工作正常!
我的目标是包含采样BBC新闻文章。txt文件,并返回此响应:
{
"entities": [
{
"name": "Mosul",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Mosul"
},
"salience": 0.16690882,
"mentions": [
{
"text": {
"content": "ir Mo",
"beginOffset": -1
}
},
{
"text": {
"content": "ar Mo",
"beginOffset": -1
}
},
{
"text": {
"content": "of Mo",
"beginOffset": -1
}
},
{
"text": {
"content": "to Mo",
"beginOffset": -1
}
}
]
},
{
"name": "US",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/United_States"
},
"salience": 0.058336213,
"mentions": [
{
"text": {
"content": "he",
"beginOffset": -1
}
},
{
"text": {
"content": "y,",
"beginOffset": -1
}
}
]
},
{
"name": "Iraqi",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Iraq"
},
"salience": 0.0219927,
"mentions": [
{
"text": {
"content": "An Ir",
"beginOffset": -1
}
},
{
"text": {
"content": "ng Ir",
"beginOffset": -1
}
},
{
"text": {
"content": "h, I",
"beginOffset": -1
}
}
]
},
{
"name": "Qusay Hamid Kadhem",
"type": "PERSON",
"metadata": {},
"salience": 0.01995722,
"mentions": [
{
"text": {
"content": "r, Qusay Hamid Kad",
"beginOffset": -1
}
}
]
},
{
"name": "Qaraqosh",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Bakhdida"
},
"salience": 0.018237775,
"mentions": [
{
"text": {
"content": "of Qaraq",
"beginOffset": -1
}
},
{
"text": {
"content": ".\r\nQaraq",
"beginOffset": -1
}
}
]
},
{
"name": "AFP",
"type": "ORGANIZATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Agence_France-Presse"
},
"salience": 0.0049931784,
"mentions": [
{
"text": {
"content": "ld ",
"beginOffset": -1
}
}
]
},
{
"name": "IS",
"type": "ORGANIZATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Islamic_State_of_Iraq_and_the_Levant"
},
}
"salience": 0.0046183467,
"mentions": [
{
"text": {
"content": "he",
"beginOffset": -1
}
},
{
"text": {
"content": "ut",
"beginOffset": -1
}
}
]
},
{
"name": "Reuters",
"type": "ORGANIZATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Reuters"
},
"salience": 0.0041254032,
"mentions": [
{
"text": {
"content": ".\r\nReut",
"beginOffset": -1
}
}
]
},
{
"name": "Christian",
"type": "PERSON",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Christian"
},
"salience": 0.0016911785,
"mentions": [
{
"text": {
"content": "st Christ",
"beginOffset": -1
}
}
]
}
],
"language": "en"
我的计划是到现在为止发送到大查询多个响应,然后数据可视按照这个伟大article