Auto Connecting to a Google Account, and show my dashboard widget on the respective website page

172 views
Skip to first unread message

Leonardo Pereira

unread,
Aug 26, 2015, 4:25:52 PM8/26/15
to Google Analytics Reporting API
Greetings
The company that I work for has several websites and manages those with a same account on google analytics.
I developed on connection with which respective website to show your dashboard on your on page using a generic user for connecting on Google Analytics; the only problem is that I need to manually authorize or already be connect to the same Google Account I've been trying to do that by (token / .p12 / and server side) but did have success. 
I'd love if some of you guys with more expertise than me, could help me. 

Thanks you for your attention and time.


unnamed.png

Matt

unread,
Aug 27, 2015, 11:04:38 AM8/27/15
to Google Analytics Reporting API
You should take a look at the Embed API - Server side Authorization example. the demo shows how you can use server-side authorization to display your Google Analytics data to users without granting them access to your Google Analytics account.
-Matt

Leonardo Silva

unread,
Aug 27, 2015, 3:40:52 PM8/27/15
to google-analytics...@googlegroups.com
Hello Matt, Thanks for answered 
I already tried this one. 
I'm developing in C# I got the connection  by server side but using ;

Johnvey.GmailAgent;
or / and 
webClient.UploadValues("https://accounts.google.com/ServiceLoginAuth?service=oz", "POST", formData);

But for both still not working for my code by on client side... 


I've been trying 

this... but need to be log in a google account

 <script>

    gapi.analytics.ready(function () {

      
        gapi.analytics.auth.authorize({
            clientid: 'clienteIDxxxxxxxxx.apps.googleusercontent.com',
            container: 'embed-api-auth-container'

        });

        var dataChart1 = new gapi.analytics.googleCharts.DataChart({
            query: {
                'ids': 'ga:8600000', 
                'start-date': '30daysAgo',
                'end-date': 'yesterday',
                'metrics': 'ga:sessions,ga:users',
                'dimensions': 'ga:date'
            },
            chart: {
                'container': 'chart-1-container',
                'type': 'LINE',
                'options': {
                    'width': '100%'
                }
            }
        });
        dataChart1.execute();

    });

    $("#embed-api-auth-container").hide();

</script>



and... this one... 


<script>

    gapi.analytics.ready(function () {

        var pheader = { "alg": "RS256", "typ": "JWT" }
        var sheader = JSON.stringify(pheader);
        var pclaim = {}; 
        pclaim.aud = "https://www.googleapis.com/oauth2/v3/token";
        pclaim.exp = KJUR.jws.IntDate.getNow();
        pclaim.iat = KJUR.jws.IntDate.getNow();
        var sclaim = JSON.stringify(pclaim);

        var key = "-----BEGIN PRIVATE KEY-----the key on my JSON generated by my "https://console.developers.google.com/project/xxx"-----END PRIVATE KEY-----\n";
        var pass = "xxxxxxvW-uhTnFAnzenc2pQ";
        var sjws = KJUR.jws.JWS.sign(null, sheader, sclaim, key, pass);
        var xhr = new XMLHttpRequest();
        var urlencodeddata = "";
        var urlencodeddatapairs = []; urlencodeddatapairs.push(encodeURIComponent("grant_type") + '=' + encodeURIComponent("urn:ietf:params:oauth:grant-type:jwt-bearer")); urlencodeddatapairs.push(encodeURIComponent("assertion") + '=' + encodeURIComponent(sjws)); urlencodeddata = urlencodeddatapairs.join('&').replace(/%20/g, '+');  // define happen if   info sent

        var token = "";

        xhr.addEventListener('load', function (event) {
            var response = JSON.parse(xhr.response);
            token = response["access_token"];
         
        });

        //gapi.analytics.auth.authorize({
        //    serverAuth: {
        //        access_token: token
        //    }
        //});


        xhr.addEventListener('error', function (event) {
            alert('oops! went wrong.')
        });
        xhr.open('post', 'https://www.googleapis.com/oauth2/v3/token');
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send(urlencodeddata)

        
       

    });


</script>




The second one brings me the token but when i tried to use for:

  gapi.analytics.auth.authorize({
            serverAuth: {
                access_token: token
            }
    });


doesn't work.



have you ever try this? do you have any idea what can be? 
already lost 2 weeks on it.
=(

Best regards



_
Leonardo Silva
.Net Development 
707.624.0715 – Cell
leonardo.pensee  Skype


--
You received this message because you are subscribed to a topic in the Google Groups "Google Analytics Reporting API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-analytics-data-export-api/jm7XpFZsWLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-analytics-data-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages