如何在google登录API中获取用户电话号码?

时间:2018-01-29 09:39:22

标签: php google-api-client

这是我的代码:

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("email");
$client->addScope("profile");
$service = new Google_Service_Oauth2($client);
$user = $service->userinfo->get(); //get user info
echo "<pre>";
print_r($user);
die;

结果是:

/*
Google_Service_Oauth2_Userinfoplus Object
(
    [internal_gapi_mappings:protected] => Array
        (
            [familyName] => family_name
            [givenName] => given_name
            [verifiedEmail] => verified_email
        )

    [email] => MyEmailName@gmail.com
    [familyName] => Martinish
    [gender] => 
    [givenName] => Martin
    [hd] => 
    [id] => 11150231528512531xxx
    [link] => https://plus.google.com/111502315285125311xxx
    [locale] => en
    [name] => Martin Martinish
    [picture] => https://lh5.googleusercontent.com/-fVHMRUGw5z4/xxx/xxx/IhHnvxaOyAw/photo.jpg
    [verifiedEmail] => 1
    [modelData:protected] => Array
        (
            [verified_email] => 1
            [given_name] => Martin
            [family_name] => Martinish
        )

    [processed:protected] => Array
        (
        )

)

现在我还需要获取用户的手机(手机)号码。我怎么能这样做?

我添加了这些范围:(根据this doc

https://www.googleapis.com/auth/contacts
https://www.googleapis.com/auth/contacts.readonly
https://www.googleapis.com/auth/user.phonenumbers.read

但结果仍然完全相同。无论如何,任何想法如何检索/实现联系人(最好是手机号码)信息?

0 个答案:

没有答案