【发布时间】:2015-08-14 18:22:55
【问题描述】:
我的电话服务器上有一个应用程序,该应用程序用于使用客户端登录访问我的 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 Apps 用户,我该怎么做呢?谷歌似乎在他们杀死客户端登录时忘记了这一点:(
【问题讨论】:
标签: php google-api google-apps google-contacts-api