【发布时间】:2015-08-02 10:55:23
【问题描述】:
我正在尝试测试 AdWords API 以了解其功能。 我不知道为什么我不断收到 AuthorizationError.USER_PERMISSION_DENIED 错误。
例如,我尝试在 AdWords 提供的 Java 客户端库示例中运行 CreateAccount.java。
这是我的步骤: 1.我创建了一个生产MCC帐户,然后得到一个“开发者令牌” 2. 我创建了一个测试 MCC 帐户,然后从控制台获取一个新的“客户端 ID”和“客户端密码”。从这里我得到了“刷新令牌” 我将“开发者令牌”(来自上面的第 1 步)、“客户端 ID”和“客户端密码”放入 ads.properties。 3. 对于 ads.properties 中的“用户代理”值,我输入了“项目 ID”的名称。 4. 对于 ads.properties 中的“客户客户 ID”值,我放置了测试 MCC 帐户客户 ID。 5. 然后我尝试在下面运行它并得到 AuthorizationError.USER_PERMISSION_DENIED 错误。
我想知道是否有任何步骤我遗漏或做错了。 提前感谢您的帮助。
下面是我尝试运行的代码。在这一行抛出异常:
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
这是完整的 sn-p(来自 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.");
}
【问题讨论】:
标签: java google-ads-api