0
我的手机服务器上有一个应用程序,用于使用客户端登录访问我的Google通讯录,以允许我的SIP电话查找他们。现在客户端登录被终止,我还没有找到一种方法来访问我的谷歌联系人的PHP,而不需要用户(我和我的妻子)来验证任何东西。如何使用服务帐户使用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中存在联系人委派,并且应用管理员也可以委派这些内容以允许服务帐户访问它。
但是,我如何以非应用程序用户身份执行此操作? Google似乎忘记了这个消息: