上传客户列表电子邮件至 Google 广告管理 API

Upload a list of customers email to Google Ads Management API

我正在尝试使用 this 指南上传经过哈希处理的客户电子邮件列表,这是我的代码。

File file = new File("/customerMatchHashed.csv");
InputStreamContent mediaContent = new InputStreamContent("application/octet-stream",
    new FileInputStream(file));
mediaContent.setLength(file.length());

try {
  Analytics analytics = initializeAnalytics();
  analytics.management().uploads().uploadData("AccountIdHere",
      "UA-123456-1", "1223334444", mediaContent).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      +  e.getDetails().getCode() + " : "
      +  e.getDetails().getMessage());
}

我继续 运行 这个错误。

There was a service error: 400 : Invalid custom data source ID format: xxxxx.

错误是不言自明的,但我不知道从哪里得到这个 custom data source ID(它应该是一个字符串),因为我在 Google 分析控制台。同样,web property Id 也是一个字符串,但我没有在控制台中看到它。 如果 help/guidance 从哪里获得这两个属性,我将不胜感激。

你应该做的第一件事是accountSummaries.list。这将为您提供当前经过身份验证的用户有权访问的所有帐户的列表。

AccountSummaries accountSummaries = service.management().accountSummaries().list().execute();

然后,一旦您在网络 属性 上找到了您已设置 data import in the google analytics admin section. You can run a custom data sources list 的帐户,这将 return 为该帐户设置的所有自定义数据源。

CustomDataSources sources = analytics.management().customDataSources().list(AccountIdFromPreviousRequest, WebpropertyIdFromPreviousReqeust).execute();

然后您可以在上传中使用 ID returned

analytics.management().uploads().uploadData(AccountIdFromFirstRequest,
                                            WebpropertyIdFromFirstReqeust,                                                
                                           customDataSourcesFromPrevousRequest,
                                           mediaContent).execute();