适用于Cloud Natural Language API的Google API密钥+访问令牌

时间:2016-12-12 16:22:23

标签: api google-api nlp google-cloud-platform access-token

我需要一个Google API密钥和一个Google Access Token来添加一些示例代码。但是,当我为Google Cloud NLP项目创建凭据时,我会获得一个包含下面发布的代码的JSON文件。哪个是API密钥,哪个是访问令牌?我很困惑,谢谢!

{
  "type": "service_account",
  "project_id": "project-id",
  "private_key_id": "some_number",
  "private_key": "-----BEGIN PRIVATE KEY-----\n....
  =\n-----END PRIVATE KEY-----\n",
  "client_email": "<api-name>api@project-id.iam.gserviceaccount.com",
  "client_id": "...",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/...<api-name>api%40project-id.iam.gserviceaccount.com"
}

1 个答案:

答案 0 :(得分:0)

您必须使用私钥才能制作签名的JWT(JSON Web令牌)。然后,您可以使用它来请求新令牌。从Google获取令牌后,您可以通过将令牌添加到HTTP标头中来将其用于后续请求:

Header Name  | value
-----------------------------
Authorization: Bearer <token>

有关所有详细信息,请参阅these Google docs