問題解決!
我意識到我沒有通過服務帳戶的密鑰文件的位置。像這樣:
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