echo userprofile facebook twitter and google

29-Jan-2016 17:15:48

dude first i want to thank you for this awesome plugin, i have install it and every thing is doing just great, but i need to call the user first name only when using one of the social login, so i added for google

$client->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));

and facebook credentials.

now when i use <?php echo $_SESSION["userprofile"]["first_name"]; it only work with facebook how can i add twitter and google also ?

thanks in advance

30-Jan-2016 06:04:06

Hi,

Data structures we get from social platfroms are not same, so you should try to print (<?php print_r($_SESSION["userprofile"]); ?>) the data array to see the value that you want to get and store it into PHP variables before display it on the screen or store it into database.

Example: When we print $_SESSION["userprofile"], we will see the first name is stored in $_SESSION["userprofile"]['first_name'] (for Facebook) and $_SESSION["userprofile"]['givenName'] (for Google). So you can check the social platform that user used to login:

<?php

if ( $_SESSION['app'] == 'facebook' ) {

$firstname = $_SESSION["userprofile"]['first_name'];

}

elseif if ( $_SESSION['app'] == 'google' ) {

$firstname = $_SESSION["userprofile"]['givenName'];

}

elseif ( $_SESSION['app'] == 'twitter' ) {

$firstname = $_SESSION["userprofile"]['screen_name'];

}

?>

Now you can display $firstname or store it into your database.

That's it.

Regards.