Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hy guys, we are developing a system which will provide users with access to Google Analytics. I'm trying to implement it in the way so user don't need to enter their Google login credentials on our site, so trying to get it work using their login.

I have a solution which gets analytics using user's email and password. I'm looking for a solution which will not require user's email and password but can not find anything.

How can it be done? any advices or links will be appreciated.

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
132 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ok, guys, after a few days of struggle I finally figured this out. There is no documentation on the Internet and people who had done it before did not want to share their success by some reason. I found this discussion which helped me.

To make it work you will need DotNetOpenAuth from http://www.dotnetopenauth.net/ and gdata from http://code.google.com/p/google-gdata/

so

using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.OAuth;

using Google.GData.Client;
using Google.GData.Analytics;

In DotNetOpenAuth there is sample project named OAuthConsumer which you need. Change it to requiest authorization for Analytics:

GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Analytics);

This will get you Token and Token secret. You can use them like this:

        GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cp", TokenManager.ConsumerKey); //ConsumerKey actually is the name of web application
        requestFactory.ConsumerKey = TokenManager.ConsumerKey;
        requestFactory.ConsumerSecret = TokenManager.ConsumerSecret;
        requestFactory.Token = AccessToken;
        requestFactory.TokenSecret = TokenManager.GetTokenSecret(AccessToken);
        requestFactory.UseSSL = true;
        AnalyticsService service = new AnalyticsService(requestFactory.ApplicationName); // acually the same as ConsumerKey
        service.RequestFactory = requestFactory;

        const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";

        DataQuery query1 = new DataQuery(dataFeedUrl);

This service you can use like here or here

And the last thing, you WILL NOT be available to try and test it on localhost so you will need a domain which MUST be registered with Google here in order to get consumer key and secret


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...