代码之家  ›  专栏  ›  技术社区  ›  orshachar

在代码中生成googlecloudapi令牌

  •  0
  • orshachar  · 技术社区  · 7 年前

    我正在尝试与一个googlecloudrestapi集成。

    使用simple rest client,我可以使用gcloud CLI生成短期API令牌:

    curl -H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" ....
    

    我尝试了本页底部的说明:

    https://developers.google.com/identity/protocols/OAuth2ServiceAccount

    1 回复  |  直到 7 年前
        1
  •  -1
  •   Luke    6 年前

    我想你可能想查看一下具体的文档 Using OAuth 2.0 with the Google API Client Library for Java

    根据您共享的文档,您可能希望继续使用Google凭据,下面是一个请求的外观示例。

    GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
    Plus plus = new Plus.builder(new NetHttpTransport(),
                                 JacksonFactory.getDefaultInstance(),
                                 credential)
        .setApplicationName("Google-PlusSample/1.0")
        .build();