如何在php中使用google-api-php-client进行谷歌联系。
我已尝试下面的代码,但无法获得联系人。是否有人对此有所了解。
$clientId = 'xxxxxxxxx';
$clientSecret = 'xxxxxx';
$redirectUrl = base_url().'login';
// Google Client Configuration
$gClient = new Google_Client();
$gClient->setApplicationName('Login to atx.com');
$gClient->setClientId($clientId);
$gClient->setClientSecret($clientSecret);
$gClient->setRedirectUri(base_url().'login');
//$gClient->addScope('profile');
//$gClient->addScope('https://www.google.com/m8/feeds');
$google_oauthV2 = new Google_Oauth2Service($gClient);
if (isset($_GET['code'])) {
$gClient->authenticate();
$this->session->set_userdata('token', $gClient->getAccessToken());
//redirect($redirectUrl);
}
$token = $this->session->userdata('token');
$token = json_decode($token,true);
$access_token = $token['access_token'];
echo "<pre>";print_r($token['access_token']);
$url = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0&oauth_token='.$token['access_token'];
// $response = file_get_contents($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response, true);
答案 0 :(得分:0)
我得到的解决方案如下点链接步骤你将在登录后获得所有联系。