【发布时间】:2015-10-17 13:44:30
【问题描述】:
我按照https://developers.google.com/identity/protocols/application-default-credentials 上的教程在 Google 应用引擎上的应用程序中使用默认凭据。但是,在本地运行应用程序时,我收到 401 错误(无效凭据)
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 好的{“代码”:401,“错误”:[{ “域”:“全球”, “位置”:“授权”, “位置类型”:“标题”, “消息”:“无效凭据”, “原因”:“authError”}],“消息”:“无效凭据”}
这是我使用的代码,包括教程的部分:
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
try{
// Authorize the request.
GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
credential = credential.createScoped(scopes);
}
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
.setApplicationName("youtube-cmdline-captions-sample").build();
} catch (IOException e) {
e.printStackTrace();
}
我已安装 Google Cloud SDK,我使用 shell 授予访问我的 google 帐户的权限
【问题讨论】:
标签: java google-app-engine oauth-2.0 credentials