问题
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.
- 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 theid
parameter you get from this request. - Wait for an hour
- 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). - 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. - 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