2017-11-09 4 views
0

google-api-php-clientを使用してGoogleの連絡先を取得する方法phpでapiを使用してGoogleの連絡先情報を取得する方法

私は以下のコードを試してみましたが、連絡先を取得できませんでした。これについて考えている人がいますか?

$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); 

答えて

関連する問題