1

I'm developing an angularjs app where Google login is one of it's features. I'm using this link to implement the feature
https://blog.codecentric.de/en/2014/06/angularjs-google-sign-integration/. Here is also the script called when the page is loaded `

<script type="text/javascript">
    (function () {
        var p = document.createElement('script');
        p.type = 'text/javascript';
        p.async = true;
        p.src = 'https://apis.google.com/js/platform.js?onload=onLoadCallback';
        var  s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(p, s);
    })();
</script>

`

Is this the right way and how I can fetch data from google and show the data to the user and if he is happy to press sign up and then to be signed. I already have my app created into the google api service and tried many options but no success so far.

Thanks in advice.

Jovan
  • 306
  • 6
  • 19

1 Answers1

1

Well this has a problem you would be login in directly with out being clicked so that might be a problem in future Try something like this

<script type="text/javascript">
      (function() {
       var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
       po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
     })();
</script>

In the view

function login() 
{
  var myParams = {
    'clientid' : 'YOUR_CLIENT_ID.apps.googleusercontent.com', //You need to set client id
    'cookiepolicy' : 'single_host_origin',
    'callback' : 'loginCallback', //callback function
    'approvalprompt':'force',
    'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'
  };
  gapi.auth.signIn(myParams);
}

Convert this codes to Angular .

Please see this question for details

Abdullah Al Noman
  • 2,728
  • 1
  • 17
  • 35
  • Can you also post the onLoadCallBack function and tell me did i need it in my app.js file because since I created id there i got an error and my app stopped working. Here is my app.js. – Jovan Aug 18 '17 at 13:43
  • `(function() { "use strict"; var app = angular.module("WebApp", [ "something" ]); app.config([ "$something", function ($something) { } ]); app.run([ "$something", function ($something) { } ]); }()); function onLoadFunction() { gapi.client.setApiKey('MyApiKey'); gapi.client.load('plus', 'v1', function () { }); }();` – Jovan Aug 18 '17 at 13:45