尝试从 google 云 java 项目访问 DoubleClick Bid Manager 合作伙伴特定私有存储桶时出现状态代码 403
Status code 403 when trying to access DoubleClick Bid Manager Partner specific private buckets from google cloud java project
大家好,
目前情况如下:
我目前有一个 google 云项目。我用于登录 google 云项目的帐户也可以登录 DoubleClick bid Manager 帐户。我的目标是使用 DoubleClick Bid Manager api 检索 DBM 存储的某些存储桶并将它们保存在我单独的 google 云项目中。
到目前为止,我可以访问 public 存储桶 (gdbm-public) 并提取和下载数据,但是当我尝试访问合作伙伴特定的桶以相同的方式,即 (gdbm-201032-201843) 我得到状态代码 403。
阅读文档 here 后,我发现我需要在 DBM 本身的 DBM 合作伙伴信息中添加一个 google 组。但是,当我尝试添加 google 组并保存更改时,我收到一条错误消息,提示更改无法保存。
这是我进行身份验证的地方:
return new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("<service_account_i_cant_show_here>")
.setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_READ_ONLY))
.setServiceAccountPrivateKeyFromP12File(new File("secret-privatekey.p12"))
.build();
然后我尝试像这样访问存储桶:
String bucketName = "gdbm-201032-201843";
GoogleCredential credentials = getCredentials();
Storage storage = new Storage(HTTP_TRANSPORT, JSON_FACTORY, credentials);
Storage.Objects.List listObjects = storage.objects().list(bucketName);
Objects objects;
do {
objects = listObjects.execute();
for (StorageObject object : objects.getItems()) {
System.out.println(object);
}
listObjects.setPageToken(objects.getNextPageToken());
} while (null != objects.getNextPageToken());
更具体地说,listObjects.execute()
是抛出 403 的地方。
我要编辑的区域是日志读取Google组和日志管理Google组在合作伙伴本身。
非常感谢任何帮助,谢谢!
我想我有一个解决方案,我使用了一种不同的身份验证方式 here。
使用链接 class 我输入了我的 google 云项目客户端凭据以及我登录到 google 云项目和 DBM 的用户。
我还将范围更改为“https://www.googleapis.com/auth/cloud-platform”,但是我不能 100% 确定这对结果有影响。
代码示例:
// Scopes for the OAuth token
private static final Set<String> SCOPES =
ImmutableSet.of("https://www.googleapis.com/auth/cloud-platform");
public static Credential getUserCredential() throws Exception {
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
JSON_FACTORY,
new InputStreamReader(SecurityUtilities.class.
getResourceAsStream("/client_secret.json")));
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// set up authorization code flow.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(dataStoreFactory)
.build();
// authorize and get credentials.
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
.authorize("<Personal user account>");
所以我没有使用服务帐户,而是使用了个人帐户。
大家好, 目前情况如下: 我目前有一个 google 云项目。我用于登录 google 云项目的帐户也可以登录 DoubleClick bid Manager 帐户。我的目标是使用 DoubleClick Bid Manager api 检索 DBM 存储的某些存储桶并将它们保存在我单独的 google 云项目中。
到目前为止,我可以访问 public 存储桶 (gdbm-public) 并提取和下载数据,但是当我尝试访问合作伙伴特定的桶以相同的方式,即 (gdbm-201032-201843) 我得到状态代码 403。
阅读文档 here 后,我发现我需要在 DBM 本身的 DBM 合作伙伴信息中添加一个 google 组。但是,当我尝试添加 google 组并保存更改时,我收到一条错误消息,提示更改无法保存。
这是我进行身份验证的地方:
return new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("<service_account_i_cant_show_here>")
.setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_READ_ONLY))
.setServiceAccountPrivateKeyFromP12File(new File("secret-privatekey.p12"))
.build();
然后我尝试像这样访问存储桶:
String bucketName = "gdbm-201032-201843";
GoogleCredential credentials = getCredentials();
Storage storage = new Storage(HTTP_TRANSPORT, JSON_FACTORY, credentials);
Storage.Objects.List listObjects = storage.objects().list(bucketName);
Objects objects;
do {
objects = listObjects.execute();
for (StorageObject object : objects.getItems()) {
System.out.println(object);
}
listObjects.setPageToken(objects.getNextPageToken());
} while (null != objects.getNextPageToken());
更具体地说,listObjects.execute()
是抛出 403 的地方。
我要编辑的区域是日志读取Google组和日志管理Google组在合作伙伴本身。
非常感谢任何帮助,谢谢!
我想我有一个解决方案,我使用了一种不同的身份验证方式 here。 使用链接 class 我输入了我的 google 云项目客户端凭据以及我登录到 google 云项目和 DBM 的用户。
我还将范围更改为“https://www.googleapis.com/auth/cloud-platform”,但是我不能 100% 确定这对结果有影响。
代码示例:
// Scopes for the OAuth token
private static final Set<String> SCOPES =
ImmutableSet.of("https://www.googleapis.com/auth/cloud-platform");
public static Credential getUserCredential() throws Exception {
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
JSON_FACTORY,
new InputStreamReader(SecurityUtilities.class.
getResourceAsStream("/client_secret.json")));
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// set up authorization code flow.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(dataStoreFactory)
.build();
// authorize and get credentials.
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
.authorize("<Personal user account>");
所以我没有使用服务帐户,而是使用了个人帐户。