Is Client Login required for pulling the data from google analytics data export API

纵然是瞬间 提交于 2019-12-25 04:55:47

问题


Coding in ASP.NET 4.0 / javascript/ jQuery/ WebServices

The Scenario

I have an analytics account i have set up at, say, some-name@gmail.com with password as pass123 I also know the table id,say ga:30037474

My question is can I pull data like

// Load the Google data JavaScript client library.
google.load('gdata', '2.x', { packages: ['analytics'] });

// Set the callback function when the library is ready.
google.setOnLoadCallback(init);

function init() {
    myService = new google.gdata.analytics.AnalyticsService('charts_sample');
//how do i securely  pull data without exposing my credentials if client login is a must
    getDataFeed();
}


/**
* Main method to get report data from the Export API.
*/
function getDataFeed() {

    myService = new google.gdata.analytics.AnalyticsService('charts_sample');
    var myFeedUri = ['https://www.google.com/analytics/feeds/data',
    '?start-date=2010-06-01',
    '&end-date=2010-06-10',
    '&dimensions=ga:day,ga:visitorType',
    '&metrics=ga:visits',
    '&sort=ga:day',
    '&max-results=20',
    '&ids=',
    'ga:30037474'].join('');

    myService.getDataFeed(myFeedUri, handleDataFeed, handleError);
}

Or shall i authenticate the client before this?

If I need to authenticate the client, it would be better if I get some pointers on how to proceed with these two requirements.
1. Cannot authenticate by exposing the user credentials on client side(Need a webservice like thing)
2. When my site loads, it should load up with the analytics data(should not ask for login then and there to pull the analytics data).

Are there any articles anywhere?


回答1:


Not sure if this answers your question. Based on the content of your question it seems you have a very good handle on the Google Analytics API. But somewhere along the line someone will need to grant access to the Google Analytics data. Using AuthSub this can be accomplished. Basically the user will need to do a one-time login to Google Analytics and "grant" your webservice a long-lived token to access their data. Once this is done you can store this token and associate it with their account, passing it when making data calls to the Google Analytics API.



来源:https://stackoverflow.com/questions/4121960/is-client-login-required-for-pulling-the-data-from-google-analytics-data-export

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