Google Drive API获得认证电子邮件


Google Drive API get authenticated email

我正在运行php-google-drive-api,我可以很好地对用户进行身份验证,但我想将用户的permissionId和他们的电子邮件地址存储到我的数据库中。使用可以很容易地访问permissionid

$service = new Google_Service_Drive($client);
...
$permissionID = $service->about->get()->getpermissionId();

但没有类似getEmailAddress()的东西。谷歌驱动器是否有电子邮件地址的返回,或者我是否需要扩展范围并在其他地方访问它?

目前我的范围是https://www.googleapis.com/auth/drive

编辑

只是通过使用进行get请求来做到这一点

https://www.googleapis.com/oauth2/v1/userinfo?access_token=

对于以前使用过这个api的人来说,存储PermissionId还是get请求返回的ID更好?我不知道两者之间的区别是

$service->about->get()->getUser()->getemailAddress();

这将为您提供通过应用程序验证的用户的电子邮件地址。

正如KRR上面提到的,访问谷歌的Drive Api参考页面了解更多功能。通常,如果你想获得一个属性值,它的形式是get($propertyname)()

CrudeCoder给出的答案对于驱动API v2是正确的。对于驱动API V3使用:

$service->about->get(array('fields' => 'user'))->getUser()->getemailAddress();

在V3中,您需要指定字段params。