2016-10-22 4 views
1

Google Cloud Shell 및 Cloud Storage를 사용하여 Google의 자연어 처리 API를 설정하려고합니다.Google Cloud Shell 및 Cloud Storage - GCS 주소에 대한 액세스 권한이 거부되었습니다.

내 문제가

, 나는 내가 특정 버킷 객체의 코드를 가리킬 때이 오류가 점점 계속 : 난

curl -s -X POST -H "Content-Type: application/json" --data-binary @requestb.json https://language.googleapis.com/v1beta1/documents:analyzeEntities?key=${NL_ 
API_KEY} 

: 이것은 내가 사용하고 코드가

{ 
    "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." 

Cloud 계정의 소유자이며 모든 프로젝트에 액세스 할 수 있습니다. 내가 여기서 누락 된 것이 있습니까?

개체를 '공개'로 설정하면 Cloud Shell에서 API 호출이 제대로 작동합니다.

이 문제에 대한 도움은 정말 감사하겠습니다.

감사합니다.

답변

1

문제가 해결되었습니다.

서비스 계정의 키 파일 위치를 전달하지 못했다는 것을 깨달았습니다. 그래서 같이 :

gcloud auth activate-service-account --key-file=service-account-key-file 

나는 (당신이보고 각 편집 할 수 있습니다 '오리온'라는 좋은 코드 편집기가있는 Google 클라우드 쉘 명령 라인에 그것을 다시 업로드 한 후, 자격 증명 영역에서 키를 다운로드하여 이런 짓을 업로드 된 파일).

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} 

위에게 :

나는 그때, Google 클라우드 스토리지에 양동이에 개체에 API를 보낼과 같이 4 단계의 코드를 수정 한 이후 3 단계 here

에서 다음 '@의 requestb.json은'나는 다음과 같은 JSON 정보가 포함 된 Google 클라우드 쉘, 업로드 다른 텍스트 파일입니다

{ 
    "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

에 따라 다음 여러 빅 쿼리에 대한 응답 및 데이터 시각화를 전송하는 것입니다
관련 문제