How to read google returned data object in PHP

I am using login in with google, google returns below details once user authorised.

Google_Service_Oauth2_Userinfoplus Object ( 
    [email] => mona123.janorkar@gmail.com 
    [familyName] => Janorkar 
    [gender] => 
    [givenName] => Mona 
    [hd] => 
    [id] => 11018813453254107047543 
    [name] => Mona Janorkar 
    [verifiedEmail] => 1 
    [data:protected] => Array ( 
    [verified_email] => 1 
    [given_name] => Mona 
    [family_name] => Janorkar ) 
    [processed:protected] => Array ( ) 
)

How i should read all the fields from above response it also have subarray.

Thank you in advance

Regards, Raj


If you have an object like this. Follow this example:

// THIS IS A SAMPLE, JUST TO SIMULATE how to access values inside
class Google_Service_Oauth2_Userinfoplus {
    public $email = 'mona123.janorkar@gmail.com';
    public $familyName = 'Janorkar';
    public $gender = null;
    public $givenName = 'Mona';
    public $hd = null;
    public $id = '11018813453254107047543';
    public $name = 'Mona Janorkar';
    public $verifiedEmail = 1;
    protected $data = array(
        'verified_email' => 1,
        'given_name' => 'Mona',
        'family_name' => 'Janorkar',

    );
    protected $processed = array();
}

// for example! this is the returned object
$object = new Google_Service_Oauth2_Userinfoplus();

// you can access the properties of the object thru the "->"
echo $object->email; // mona123.janorkar@gmail.com

Supplemental Info: This topic is also tackled here

What is the "->" PHP operator called and how do you say it when reading code out loud?

Where do we use the object operator "->" in PHP?

链接地址: http://www.djcxy.com/p/58154.html

上一篇: >'在PHP和MySQL

下一篇: 如何在PHP中读取google返回的数据对象