java - 尝试从 Google Cloud Java 项目访问 DoubleClick Bid Manager 合作伙伴特定的私有(private)存储桶时出现状态代码 403

标签 java google-cloud-storage google-cloud-platform double-click-advertising

大家好, 目前情况如下: 我目前有一个谷歌云项目。我登录 Google Cloud 项目的帐户也可以登录 DoubleClick bid Manager 帐户。我的目标是使用 DoubleClick Bid Manager API 检索 DBM 存储的某些存储桶并将它们保存在我单独的 Google Cloud 项目中。

到目前为止,我可以访问公共(public)存储桶(gdbm-public)并提取和下载数据,但是当我尝试以相同方式访问合作伙伴特定存储桶时,即(gdbm-201032-201843),我收到状态代码403。

阅读文档后 here ,我发现我需要在 DBM 本身的 DBM 合作伙伴信息中添加一个 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 。 使用我在谷歌云项目客户端凭据中输入的链接类以及我登录谷歌云项目和 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>");

因此,我没有使用服务帐户,而是使用了个人帐户。

关于java - 尝试从 Google Cloud Java 项目访问 DoubleClick Bid Manager 合作伙伴特定的私有(private)存储桶时出现状态代码 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41508202/

相关文章:

java - 测试时老虎机问题

google-cloud-storage - 将 Google Cloud Storage 与 rsync 结合使用

google-bigquery - 使用 Google Data Studio 分析 Google Cloud Datastore 中的数据

python - 如何使用谷歌云 Python API 将目录复制到谷歌云存储?

redis - SaltStack 作业检测

java - 构造函数 Object(Context, int, List<DrawerItem>) 未定义

java - 在 Java 中获取包含 BufferedImage 中非透明像素的区域

java - 具有静态属性的同步块(synchronized block) vs 共享属性 vs 同步方法

python - 带有 gspythonlibrary 的 Google 云存储

google-cloud-platform - 如何在 Google Compute Engine 中打开特定端口(例如 9090)