Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

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. And it does. I am able to get AccountID but I am not able to upload my Cost Data. I don't know what is wrong... but it gets stuck when it tries to get the Upload object.

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.

like image 648
Kapitán Mlíko Avatar asked Sep 04 '26 04:09

Kapitán Mlíko


1 Answers

Turns out that I downloaded java client library 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

I found both in Developer Guide client libraries link

But today I found rev26-1.13.2-beta here and used it in my solution. 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. There are many missleading links in Google Guides and what I found I reported via Google Groups. 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.

But problem is there was no sign of newer version... I downloaded what I thought was the newest from their mercurial repository. 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.

like image 72
Kapitán Mlíko Avatar answered Sep 06 '26 17:09

Kapitán Mlíko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!