AuthorizationError.USER_PERMISSION_DENIED 针对测试 MCC 帐户进行测试时(创建帐户)
AuthorizationError.USER_PERMISSION_DENIED when testing against test MCC account (Creating Account)
我正在尝试测试 AdWords API 以了解其功能。
我不明白为什么我总是收到 AuthorizationError.USER_PERMISSION_DENIED 错误。
例如,我在 AdWords 提供的 Java 客户端库示例中尝试 运行 CreateAccount.java。
这是我的步骤:
1. 我创建了一个生产 MCC 帐户,然后得到一个 "Developer Token"
2. 我创建了一个测试 MCC 帐户,然后从控制台获得了一个新的 "Client ID" 和 "Client Secret"。由此我得到了 "Refresh Token"
我将 "Developer Token"(来自上面的步骤 #1)、"Client ID" 和 "Client Secret" 放入 ads.properties。
3. 对于 ads.properties 中的 "user agent" 值,我输入了 "Project ID" 的名称。
4. 对于 ads.properties 中的 "client customer id" 值,我放置了测试 MCC 帐户客户 ID。
5. 然后我在下面尝试 运行 并得到 AuthorizationError.USER_PERMISSION_DENIED 错误。
我想知道我是否遗漏或做错了任何步骤。
预先感谢您的帮助。
下面是我正在尝试的代码 运行。此行抛出异常:
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
这是完整的代码段(来自 AdWords 代码示例)
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
// and can be used in place of a service account.
Credential oAuth2Credential = new OfflineCredentials.Builder()
.forApi(Api.ADWORDS)
.fromFile()
.build()
.generateCredential();
// Construct an AdWordsSession.
AdWordsSession session = new AdWordsSession.Builder()
.fromFile()
.withOAuth2Credential(oAuth2Credential)
.build();
AdWordsServices adWordsServices = new AdWordsServices();
// Get the CampaignService.
ManagedCustomerServiceInterface managedCustomerService =
adWordsServices.get(session, ManagedCustomerServiceInterface.class);
// Create account.
ManagedCustomer customer = new ManagedCustomer();
customer.setName("Customer created with ManagedCustomerService on " + new DateTime());
customer.setCurrencyCode("EUR");
customer.setDateTimeZone("Europe/London");
// Create operations.
ManagedCustomerOperation operation = new ManagedCustomerOperation();
operation.setOperand(customer);
operation.setOperator(Operator.ADD);
ManagedCustomerOperation[] operations = new ManagedCustomerOperation[ {operation};
// Add account.
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
// Display accounts.
for (ManagedCustomer customerResult : result.getValue()) {
System.out.println("Account with customer ID \"" + customerResult.getCustomerId()
+ "\" was created.");
}
我想你已经完成了这些步骤:
1] 在 Google Developer Console 上创建了一个应用程序,并获得了 ads.properties 的这些值:
api.adwords.clientId 和 api.adwords.clientSecret
2] 然后,您在获得 developerToken 的地方创建生产 MCC 帐户。将其放入 ads.properties.
3] 然后创建 MCC 测试帐户,您可以在其中获得主 mcc 帐户的 adwords id,您可能已将其放入 ads.properties.
4] 然后你使用 运行ning GetRefreshToken.java 从 google 团队提供的示例中获得刷新令牌。(在 运行ning [=34= 之后重新检查这里] 你 post url 进入浏览器的 java 输出控制台,并通过登录你的测试 mcc gmail 帐户授予此应用程序的权限。然后你会在浏览器中得到一些字符串 window。将该字符串作为输入复制到 java 输出控制台,然后按回车键。在此阶段,您将获得真正的 refreshToken 作为 java 输出控制台中的输出,将其复制到您的 ads.properties)。
5] 将此设置用户代理设置为某个随机字符串后。
6] 然后 运行 java 程序 CreateAccount.java 来自 google 团队提供的样本。
7] 这应该有效。
大多数时候人们在生成 refreshToken 时犯了错误,请按照 "GetRefreshToken.java" 的过程一步步进行。
确保您使用正确的 MMC 授予权限。
如果要查看测试客户端数据,则必须在登录 TEST MCC 时复制 GetRefreshToken 生成的 link。如果你想查看产品。客户端数据,您在登录产品时复制 GetRefreshToken 生成的 link。中冶
这里是完整的文档:
https://developers.google.com/adwords/api/docs/test-accounts
我正在尝试测试 AdWords API 以了解其功能。 我不明白为什么我总是收到 AuthorizationError.USER_PERMISSION_DENIED 错误。
例如,我在 AdWords 提供的 Java 客户端库示例中尝试 运行 CreateAccount.java。
这是我的步骤: 1. 我创建了一个生产 MCC 帐户,然后得到一个 "Developer Token" 2. 我创建了一个测试 MCC 帐户,然后从控制台获得了一个新的 "Client ID" 和 "Client Secret"。由此我得到了 "Refresh Token" 我将 "Developer Token"(来自上面的步骤 #1)、"Client ID" 和 "Client Secret" 放入 ads.properties。 3. 对于 ads.properties 中的 "user agent" 值,我输入了 "Project ID" 的名称。 4. 对于 ads.properties 中的 "client customer id" 值,我放置了测试 MCC 帐户客户 ID。 5. 然后我在下面尝试 运行 并得到 AuthorizationError.USER_PERMISSION_DENIED 错误。
我想知道我是否遗漏或做错了任何步骤。 预先感谢您的帮助。
下面是我正在尝试的代码 运行。此行抛出异常:
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
这是完整的代码段(来自 AdWords 代码示例)
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
// and can be used in place of a service account.
Credential oAuth2Credential = new OfflineCredentials.Builder()
.forApi(Api.ADWORDS)
.fromFile()
.build()
.generateCredential();
// Construct an AdWordsSession.
AdWordsSession session = new AdWordsSession.Builder()
.fromFile()
.withOAuth2Credential(oAuth2Credential)
.build();
AdWordsServices adWordsServices = new AdWordsServices();
// Get the CampaignService.
ManagedCustomerServiceInterface managedCustomerService =
adWordsServices.get(session, ManagedCustomerServiceInterface.class);
// Create account.
ManagedCustomer customer = new ManagedCustomer();
customer.setName("Customer created with ManagedCustomerService on " + new DateTime());
customer.setCurrencyCode("EUR");
customer.setDateTimeZone("Europe/London");
// Create operations.
ManagedCustomerOperation operation = new ManagedCustomerOperation();
operation.setOperand(customer);
operation.setOperator(Operator.ADD);
ManagedCustomerOperation[] operations = new ManagedCustomerOperation[ {operation};
// Add account.
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
// Display accounts.
for (ManagedCustomer customerResult : result.getValue()) {
System.out.println("Account with customer ID \"" + customerResult.getCustomerId()
+ "\" was created.");
}
我想你已经完成了这些步骤:
1] 在 Google Developer Console 上创建了一个应用程序,并获得了 ads.properties 的这些值: api.adwords.clientId 和 api.adwords.clientSecret
2] 然后,您在获得 developerToken 的地方创建生产 MCC 帐户。将其放入 ads.properties.
3] 然后创建 MCC 测试帐户,您可以在其中获得主 mcc 帐户的 adwords id,您可能已将其放入 ads.properties.
4] 然后你使用 运行ning GetRefreshToken.java 从 google 团队提供的示例中获得刷新令牌。(在 运行ning [=34= 之后重新检查这里] 你 post url 进入浏览器的 java 输出控制台,并通过登录你的测试 mcc gmail 帐户授予此应用程序的权限。然后你会在浏览器中得到一些字符串 window。将该字符串作为输入复制到 java 输出控制台,然后按回车键。在此阶段,您将获得真正的 refreshToken 作为 java 输出控制台中的输出,将其复制到您的 ads.properties)。
5] 将此设置用户代理设置为某个随机字符串后。
6] 然后 运行 java 程序 CreateAccount.java 来自 google 团队提供的样本。
7] 这应该有效。
大多数时候人们在生成 refreshToken 时犯了错误,请按照 "GetRefreshToken.java" 的过程一步步进行。
确保您使用正确的 MMC 授予权限。 如果要查看测试客户端数据,则必须在登录 TEST MCC 时复制 GetRefreshToken 生成的 link。如果你想查看产品。客户端数据,您在登录产品时复制 GetRefreshToken 生成的 link。中冶
这里是完整的文档: https://developers.google.com/adwords/api/docs/test-accounts