【问题标题】:How to set Credentials for Publisher for Google PubSub如何为 Google PubSub 的发布者设置凭据
【发布时间】:2017-05-30 21:25:54
【问题描述】:

我正在使用更新版本的 PubSub - Publisher API

我有一个 P12 文件,并且正在构建这样的凭据:

GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(transport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(serviceAccount)
            .setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/pubsub")) 
            .setServiceAccountPrivateKeyFromP12File(new File(keyFile))
            .build();

如何在 Publisher 上设置凭据? 另外,有没有办法获取静态范围字符串"https://www.googleapis.com/auth/pubsub"

【问题讨论】:

标签: google-cloud-pubsub


【解决方案1】:

我发现问题已回答here,以防万一有人遇到这个问题:

基本上,

Publisher
  .defaultBuilder(topic)
  .setChannelProvider(TopicAdminSettings
  .defaultChannelProviderBuilder()
  .setCredentialsProvider(FixedCredentialsProvider.create(yourCredentialsHere))
  .build())
.build();

【讨论】:

  • 唯一的问题是这需要 json 版本的密钥而不是 P12
猜你喜欢
  • 1970-01-01
  • 2015-10-02
  • 2020-06-22
  • 2022-12-10
  • 2018-11-02
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多