2015-08-14 50 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。

相關問題