2015-08-14 49 views
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似乎忘记了这个消息:

回答

0

服务帐号不是你,并且默认情况下不能访问任何数据。将服务帐号视为虚拟用户如果你将服务帐号电子邮件地址,并将其作为用户添加到您的谷歌驱动器中的文件夹中,它将有权访问谷歌驱动器上的该文件夹。如果您获取服务帐户电子邮件地址,并允许其访问Google日历中的某个日历,日历。

没有办法,据我所知,授予您的谷歌联系人的用户访问。

我建议您尝试使用了OAuth2。

相关问题