1

I have a very simple page in Angular2, which contains a google Sign in button. Here is my code :

login.html

<meta name="google-signin-client_id" content="MYID.apps.googleusercontent.com">

<script>
    function onSignIn(googleUser) {
        var profile = googleUser.getBasicProfile();
        console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
        console.log('Name: ' + profile.getName());
        console.log('Image URL: ' + profile.getImageUrl());
        console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    }
</script>

<div class="g-signin2 google-connect" data-onsuccess="onSignIn"></div>

login.ts

ngOnInit(){
    var script = document.createElement('script');
    script.src = 'https://apis.google.com/js/platform.js';
    document.body.appendChild(script);
  }
// This code simply loads the JS after the page is rendered, since it doesn't work with only the script tag on the top of the HTML


The button is working very well, I can sign in perfectly, but I can't get the user informations. The onSignIn function is not triggering.

I've tried to change the data-onsuccess by multiple directives, I created functions inside my controller, or let the one google provides in my HTML, but I have no output on my console. I can't manage to retrieved the data of a connection. I'd juste like to get basic informations of an user (ID and mail). I can't use Angular2 plugins since i'm developing under Ionic. Thank you in avance for any help :)

saperlipopette
  • 1,603
  • 12
  • 26
  • 1
    I was searching on the same topic and found this -> https://stackoverflow.com/questions/42458346/need-to-insert-script-tag-in- angular-2 – user1818489 Sep 06 '17 at 14:46

0 Answers0