我遵循Management API - Daily Upload Developer Guide并创建了已安装的 Java 应用程序以将成本数据上传到 Google Analytics。但它不知何故不起作用。我已经Analytics
创建了授权https://www.googleapis.com/auth/analytics
范围的服务,现在我想上传一些成本数据。
我是按照上面提到的指南这样做的。
File file = new File("data.csv");
InputStreamContent mediaContent = new InputStreamContent('application/octet-stream', new FileInputStream(file));
mediaContent.setLength(file.length());
// You can ignore following three lines... those are there to make sure Analytics service works.
Accounts accounts = analytics.management().accounts().list().execute();
Account account = accounts.getItems().get(0);
System.out.println("Account ID is: " + account.getId());
Analytics.Management management = analytics.management();
Analytics.Management.DailyUploads dailyUploads = management.dailyUploads();
// Here it gets stuck!
Analytics.Management.DailyUploads.Upload upload = dailyUploads.upload("AccountID",
"PropertyID", "CustomDataSourceID", "yyyy-MM-dd", 1, "cost", mediaContent);
upload.setReset(true);
DailyUploadAppend append = upload.execute();
我添加了一些行来检索Accounts
和打印第一个的AccountIDAccount
......只是为了确保它Analytics service
有效。它确实如此。我可以获得AccountID,但无法上传我的成本数据。我不知道出了什么问题......但是当它试图获取Upload
对象时它会卡住。
它不会抛出异常。它只是保持在那里,什么也不做。有什么我想念的吗?我将不胜感激任何帮助。