使用com.google.cloud.google-云库(http://googlecloudplatform.github.io/google-cloud-java/0.21.1/index.html),我为Google Cloud Platform发布/订阅提供了以下代码:Google云端平台pub/sub发布者,如何提供除默认应用程序凭据以外的凭据
TopicName topicName = TopicName.create("projectId...", "topic...");
Publisher pub = Publisher.defaultBuilder(topicName).build();
如何提供发布者使用的凭据?我已经将它们存储在内存中,因为它们是通过其他方式提供的,而不是将它们硬编码到文件中。是
所有使用定制凭证示例如下:
Storage storage = StorageOptions.newBuilder()
.setProjectId(PROJECT_ID)
.setCredentials(GoogleCredentials.fromStream(
new FileInputStream(PATH_TO_JSON_KEY))).build();
Bucket bucket = storage.create(BucketInfo.of("myBucketName"));
但没有PubSubOptions或PublisherOptions类写类似的代码(我更换的FileInputStream有一个ByteArrayInputStream)。
这里是谁的人有同样的问题,但代码示例不工作:https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1751
此位:“FixedCredentialsProvider.create(凭证)”正是我所需要的!谢谢! – RedShift
后续问题,你是从哪里得到的?我一直在搜索并阅读一小时内的文档: - \ – RedShift
@RedShift:只是浏览源代码 - 但有明显的优势,我在C#的客户端库团队工作,而库不是* *不同...所以我有点知道在哪里看:)我已经在答案的底部添加了更多的细节。 –