java - DataFlow SDK 2.x:PubSubIO 授权错误
问题描述
使用 Dataflow Java SDK 2 从 Pubsub 读取
我正在尝试如下:
public class App2 {
public static void main(String[] args) {
Pipeline pipeline = Pipeline.create(PipelineOptionsFactory.fromArgs(args).create());
pipeline
.apply("ReadStrinsFromPubsub",
PubsubIO.readStrings().fromTopic("projects/dev/topics/trading"))
.apply("PrintToStdout", ParDo.of(new DoFn<String, Void>() {
@ProcessElement
public void processElement(ProcessContext c) {
System.out.printf("Received at %s : %s\n", Instant.now(), c.element()); // debug log
}
}));
pipeline.run().waitUntilFinish();
}
}
发生错误的原因是:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "The request is missing a valid API key.",
"reason" : "forbidden"
} ],
"message" : "The request is missing a valid API key.",
"status" : "PERMISSION_DENIED"
}
我该如何解决?
解决方案
gcloud auth application-default login
将使您能够使用登录机器上的默认服务帐户。
推荐阅读
- python - Heroku 部署 plotly-dash 应用程序 - 构建失败
- rest - Apache Camel REST DSL deadLetterChannel
- bash - sed:在文件最后一行的位置搜索和替换值
- python - 如何抓取具有用户名和密码的网站?
- python - 通过谷歌 API 和 Python 将照片上传到谷歌照片
- azure - 简化 PowerShell Runbook 以发送电子邮件
- java - 使用 JPA 和 ManyToMany 删除
- python - 检索传递给取消的协程/任务的参数
- python - 更新 Django REST 框架中的 SerializerMethodField
- php - 更改 Laravel 中翻译功能的默认行为