我正在尝试测试 AdWords API 以了解其功能。 我不明白为什么我不断收到 AuthorizationError.USER_PERMISSION_DENIED 错误。
例如,我尝试在 AdWords 提供的 Java 客户端库示例中运行 CreateAccount.java。
这是我的步骤: 1.我创建了一个生产MCC帐户,然后获得了“开发者 token ” 2. 我创建了一个测试 MCC 帐户,然后从控制台获取新的“客户端 ID”和“客户端 key ”。由此我得到了“刷新 token ” 我将“开发者 token ”(来自上面的第 1 步)、“客户端 ID”和“客户端 key ”放入 ads.properties。 3. 对于 ads.properties 中的“用户代理”值,我输入了“项目 ID”的名称。 4. 对于 ads.properties 中的“客户客户 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 开发者控制台上创建了一个应用,并获取了 ads.properties 的以下值: api.adwords.clientId 和 api.adwords.clientSecret
2] 然后您创建生产 MCC 帐户,并在其中获得了开发者 token 。将其放入 ads.properties 中。
3] 然后创建 MCC 测试帐户,您已在其中获得了主 mcc 帐户的 adwords ID,您可能已将其放入 ads.properties 中。
4] 然后,您可以通过运行 Google 团队提供的示例中的 GetRefreshToken.java 来获取刷新 token 。(在此处重新检查,运行 GetRefreshToken.java 后,您将在 java 输出控制台上获得的 url 发布到浏览器,并通过登录授予此应用程序的权限进入您的测试 mcc gmail 帐户。然后您会在浏览器窗口中看到一些字符串。将该字符串作为输入复制到 java 输出控制台,然后按 Enter 键。在此阶段,您将获得真正的刷新 token 作为 java 输出控制台中的输出,将其复制到您的广告.属性)。
5]将此 set useragent 设置为某个随机字符串后。
6] 然后运行 Google 团队提供的示例中的 Java 程序 CreateAccount.java。
7] 这应该有效。
大多数时候,人们在生成刷新 token 时会犯错误,一步一步地遵循“GetRefreshToken.java”的过程。
关于java - 针对测试 MCC 帐户(创建帐户)进行测试时出现 AuthorizationError.USER_PERMISSION_DENIED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30362454/