简体   繁体   English

Google AnalyticsAPI成本数据上传陷入困境

[英]Google Analytics API Cost Data Upload stuck

I followed Management API - Daily Upload Developer Guide and created installed java application to upload Cost Data to Google Analytics. 我按照Management API - 每日上传开发人员指南创建了已安装的Java应用程序, 将成本数据上传到Google Analytics。 But It somehow doesn't work. 但它不知何故不起作用。 I have Analytics service created authorized with https://www.googleapis.com/auth/analytics scope and now I want to upload some Cost Data. 我已通过https://www.googleapis.com/auth/analytics范围授权创建Analytics服务,现在我想上传一些费用数据。

I did it according to mentioned Guide like this. 我按照提到的指南这样做了。

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();

I added some lines to retrieve Accounts and print AccountID of the first Account ... just to be sure that Analytics service works. 我添加了一些行来检索Accounts并打印第一个Account AccountID ...以确保Analytics service正常运行。 And it does. 确实如此。 I am able to get AccountID but I am not able to upload my Cost Data. 我可以获得AccountID,但我无法上传我的费用数据。 I don't know what is wrong... but it gets stuck when it tries to get the Upload object. 我不知道出了什么问题......但是当它试图获取Upload对象时它会被卡住。

It doesn't throw Exception. 它不会抛出异常。 It just holds there and does nothing. 它只是在那里,什么都不做。 Is there something I am missing? 有什么我想念的吗? I will be grateful for any help. 我将不胜感激任何帮助。

Turns out that I downloaded java client library 1.13.2. 原来我下载了java客户端库1.13.2。 from here 这里开始

Java Client Library doesn't contain Management API google-api-services-analytics-v3 So I downloaded the newest from here it was v3-rev20-1.8.0-beta Java客户端库不包含管理API google-api-services-analytics-v3所以我从这里下载了最新版本的v3-rev20-1.8.0-beta

I found both in Developer Guide client libraries link 我在Developer Guide 客户端库链接中找到了它们

But today I found rev26-1.13.2-beta here and used it in my solution. 但今天我在这里找到了rev26-1.13.2-beta并在我的解决方案中使用了它。 Now Everything works, so it was just an incompatibility issue caused by misleading links in Developer Guide. 现在一切正常,所以这只是由于开发者指南中误导性链接引起的不兼容问题。

EDIT 编辑

For people struggling with this problem in the future. 对于将来挣扎于这个问题的人们。 Be sure your libraries are compatible. 确保您的库兼容。 As you can see I was able to GET AccountID of the first Account so I thought everything was OK, but it wasn't. 正如您所看到的,我能够获得第一个帐户的AccountID,所以我认为一切都很好,但事实并非如此。 There are many missleading links in Google Guides and what I found I reported via Google Groups. Google指南中有许多具有误导性的链接以及我通过Google网上论坛报告的内容。 For me there was a hint. 对我来说有一个暗示。 I had google-api-java-client- 1.13.2 -beta and google-api-services-analytics-v3-rev20- 1.8.0 -beta . 我有google-api-java-client- 1.13.2 -betagoogle-api-services-analytics-v3-rev20- 1.8.0 -beta

But problem is there was no sign of newer version... I downloaded what I thought was the newest from their mercurial repository. 但问题是没有更新版本的迹象......我从他们的mercurial存储库下载了我认为最新的东西。 And still there was a newer version accessible only from one link somewhere deep in developers guide. 而且还有一个较新的版本只能从开发人员指南深处的一个链接访问。 I hope it will be better in the future. 我希望将来会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM