How to store unsampled reports from Google Analytics API to Google Drive?

允我心安 提交于 2019-12-11 13:02:42

问题


I read this instruction on how to retrieve data for unsampled reports from Google Analytics API to Google Drive: https://developers.google.com/analytics/devguides/config/mgmt/v3/unsampled-reports#introduction

As far as I understand, here are the steps to retrieve unsampled reports: 1. Store the unsampled reports to Google Drive API 2. Use Drive API to download the file

However, I couldn't find the instructions on how to store the unsampled reports to Google Drive API. Could you please tell me in details on how to do this? Also if you could, please tell me how to use Drive API to download the file as well.

Thank you in advance.


回答1:


First of all, Unsampled Report is only available to Google Analytics 360 (Previously Google Analytics Premium) users. So if you use only the free version of the product this feature is simply not available, the API should give you an error.

The Unsampled API has 3 methods:

  • insert - Creates a new Unsampled Report
  • get - Get the status of a given Unsampled Report
  • list - list the status of all unsampled reports you created in a given profileId

Now you have to keep in mind that Unsampled Reports can take a few hours to be generated. So the dynamics of using the Unsampled Reporting API are obviously a bit different from the Core Reporting API. After a query on the Core Reporting API you get the results right away. With the Unsampled API you just create a report and have to wait for it to be ready.

Here's, roughly, how exporting data from the Unsampled API works.

  1. Use the insert method on the API to create a new Unsampled Report. The Response will probably have a status: PENDING which means the report is being processed. You want to store the id parameter you get from this request.
  2. Wait for an hour
  3. Use the id from step (1) and issue a get request to the API. This will give you the current status of the unsampled report. If this is still PENDING go back to step (2).
  4. If the status is COMPLETE the report should be complete and already waiting for you in Google Drive. The API should return a driveDownloadDetails.documentId you want to store this.
  5. Use the Google Drive API to fetch the contents of the file reference you got from step (4)


来源:https://stackoverflow.com/questions/36366728/how-to-store-unsampled-reports-from-google-analytics-api-to-google-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!