![](/img/trans.png)
[英]How do I authorize a google drive service account access to a google account without using google apps?
[英]How do I access my Google Contacts with PHP using a service account?
我的电话服务器上有一个应用程序,该应用程序用于使用“客户端登录”访问我的Google联系人,以允许我的SIP电话查找它们。 现在,客户端登录已被杀死,我还没有找到一种无需使用用户(我和我的妻子)进行身份验证即可使用PHP访问我的Google联系人的方法。
// create the instance of the Google Client
$this->googleclient = new Google_Client();
$this->googleclient->setApplicationName(GOOGLE_CLIENTID);
// define the credentials and access level (analytics readonly)
$credentials = new Google_Auth_AssertionCredentials(
GOOGLE_EMAIL,
array(
'https://www.googleapis.com/auth/contacts.readonly',
),
file_get_contents("config/key.p12"),
"notasecret"
);
// set the user it wants to impersonate
$credentials->sub = GOOGLE_USER;
// throw the credentials into the client object
$this->googleclient->setAssertionCredentials($credentials);
// authenticate the application and fetch the token
$this->googleclient->setClientId(GOOGLE_CLIENTID);
$this->googleclient->getAuth()->refreshTokenWithAssertion();
$tokenData = json_decode($this->googleclient->getAccessToken());
$accessToken = $tokenData->access_token;
$val = file_get_contents("https://www.google.com/m8/feeds/contacts/".GOOGLE_USER."/full"
."?v=3.0&access_token=".$accessToken);
print_r($val);
当我删除GOOGLE_USER常量并仅允许服务帐户访问其自己的数据时,该方法就起作用了,但这不是我的联系方式,也不是我妻子的联系方式。 我知道Google Apps中有联系人委派,而且Apps管理员也可以委派这些内容以允许服务帐户访问它。
但是,作为非应用程序用户我该如何做呢? 似乎Google杀死了Client Login时忘记了这个:
服务帐户不是您,默认情况下也无权访问任何数据。 将服务帐户视为虚拟用户。 如果您使用服务帐户的电子邮件地址并将其作为用户添加到您的Google驱动器的文件夹中,则可以访问该Google驱动器上的文件夹。 如果您使用服务帐户的电子邮件地址并允许其访问您在Google日历上的日历之一,它将有权访问该日历。
据我所知,无法授予其他用户访问您的Google联系人的权限。
我建议您尝试使用Oauth2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.