1

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

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

在阅读此处的文档后,我发现我需要在 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 的地方。

我正在尝试编辑的区域是合作伙伴本身的Log Read Google GroupLog Management Google Group

非常感谢任何帮助,谢谢!

4

1 回答 1

0

我想我有一个解决方案,我使用了不同的身份验证方式,如此处所示。使用我在我的谷歌云项目客户端凭据中输入的链接类以及我登录谷歌云项目和 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>");

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

于 2017-01-09T15:54:18.807 回答