我目前正在使用 Google_Client api 并希望获取用户名、电话、电子邮件和用户地址。
我设置了这些范围:
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/user.birthday.read',
'https://www.googleapis.com/auth/user.addresses.read',
'https://www.googleapis.com/auth/user.emails.read',
'https://www.googleapis.com/auth/user.phonenumbers.read'
当我点击谷歌登录时,它会询问正确的权限,然后我使用谷歌提供的代码获取访问令牌。
获得令牌后,我请求people_service
和配置文件数据如下:
$token = $this->client->fetchAccessTokenWithAuthCode($_GET['code']);
$people_service = new \Google_Service_PeopleService($this->client);
$profile = $people_service->people->get(
'people/me',
array('personFields' => 'addresses,birthdays,emailAddresses,phoneNumbers')
);
它返回一个Google_Service_PeopleService_Person
对象。
但是当我尝试在它上面使用方法时,它getPhoneNumbers()
会返回一个 Call to undefined method Google_Service_PeopleService_Person::getNames()
错误。
有什么问题,我该怎么办?