figaro
figaro

Reputation: 2325

How to set Credentials for Publisher for Google PubSub

I am using the newer version of PubSub - Publisher API

I have a P12 file and am building the credential like this:

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();

How do I set the credentials on the Publisher? Also, is there a way to get the static scope string "https://www.googleapis.com/auth/pubsub"

Upvotes: 2

Views: 2472

Answers (1)

figaro
figaro

Reputation: 2325

I found the question answered here in case anyone runs into this:

Basically,

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

Upvotes: 2

Related Questions