1

PHP 용 Google Api 클라이언트의 최신 버전에서는 작동하는 예제가 나오지 않습니다. 문서도 매우 슬림 .. 필자는 많이 시도하고 로그인/인증 방법을 알아낼 수 없으므로 Fusion Tables에 삽입/삽입 할 수 있습니다. Ive는 oAuth 및 서비스 토큰 (p12 파일 포함)을 시도했습니다.Google Api 클라이언트 PHP - 퓨전 테이블 만들기

퓨전 테이블에서 데이터를 검색하고 FireBug (FirePHP 사용)에 기록 할 수 있습니다. 그러나 개발자 ID와 인증이 필요하지 않습니다.

누군가가 매우 훌륭한 사례를 갖고 있다면 이드는 매우 감사합니다!

내 임상 시험 :

class GoogleClass { 

    protected $firephp; 

    public function init() { 
     session_start(); 

     require_once 'Google/Client.php'; 
     require_once 'Google/Auth/AssertionCredentials.php'; 
     #require_once 'Google/Auth/OAuth2.php'; 
     require_once 'Google/Service/Fusiontables.php'; 
     #require_once 'Google/Service/Urlshortener.php'; 
     #require_once 'Google/Service/Oauth2.php'; 



     /* 
      Service Auth 
     $client_id = 'client_id'; 
     $service_account_name = 'service_account_name'; 
     $key_file_location = 'key_file_location'; 

     $client = new Google_Client(); 
     $client->setApplicationName('FusionTableConnect'); 

     if (isset($_SESSION['service_token'])) { 
      $client->setAccessToken($_SESSION['service_token']); 
     } 
     $key = file_get_contents($key_file_location); 
     $cred = new Google_Auth_AssertionCredentials(
      $service_account_name, 
      array('http://www.googleapis.com/auth/fusiontables'), 
      $key 
     ); 
     $client->setAssertionCredentials($cred); 
     if ($client->getAuth()->isAccessTokenExpired()) { 
      try { 
       $client->getAuth()->refreshTokenWithAssertion($cred); 
      } catch (Exception $e) { 
       $this->firephp->error($e); 
      } 
     } 
     $_SESSION['service_token'] = $client->getAccessToken(); 
     */ 


     /* 
      Execute Query to get Table results 
     */ 
     $client = new Google_Client(); 
     $client->setDeveloperKey('developerKeyServer');        // Server Application API key - Query 

     $tableId = 'tableId'; 
     $ft = new Google_Service_Fusiontables($client); 
     try { 
      $result = $ft->query->sql("SELECT gm_code FROM $tableId"); 
      $this->firephp->log($result, 'Array'); 
     } catch (Exception $e) { 
      $this->firephp->error($e); 
     } 

/*   ------------------------------------------------------------------------------ */ 

     /* 
      Google Client setup 
     $client = new Google_Client(); 
     #$client->setApplicationName('TestApp'); 
     $client->setClientId('clientId');           // Web application Client ID 
     $client->setClientSecret('clientSecret');         // Web application Secret key 
     #$client->addScope('https://www.googleapis.com/auth/fusiontables');   // Fusion Tables scope 
     $client->setRedirectUri('redirectUri'); 

     #$client->setDeveloperKey('developerKeyServer');       // Server Application API key - Query 
     #$client->setDeveloperKey('developerKeyBrowser');       // Browser Application API key 
     */ 



     /* 
      oAuth2 Identification 
     $service = new Google_Service_Urlshortener($client); 
     #$client->addScope(Google_Service_Urlshortener::URLSHORTENER); 
     $client->setScopes("https://www.googleapis.com/auth/plus.login"); 
     $authUrl = $client->createAuthUrl(); 

     if (isset($_GET['code'])) { 
      $client->authenticate($_GET['code']); 
      $_SESSION['access_token'] = $client->getAccessToken(); 
      $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 
      header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 
     } 

     if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 
      $client->setAccessToken($_SESSION['access_token']); 
     } 
     */ 



     /* 
      Fusion Tables 
     $service = new Google_Service_Fusiontables($client); 
     try { 
      $result = $service->query->sql("SELECT gm_code FROM tableId"); 
      $this->firephp->log($result, 'Array'); 
     } catch (Exception $e) { 
      $this->firephp->error($e); 
     } 

     $column = new Google_Service_Fusiontables_Column(); 
     $column->setName('foo'); 
     $column->setType('STRING'); 

     $table = new Google_Service_Fusiontables_Table(); 
     $table->setName('bar'); 
     $table->setColumns(array($column)); 

     try { 
      $service->table->insert($table); 
     } catch(Exception $e) { 
      $this->firephp->error($e); 
     }*/ 
    } 

    public function firePHPInit($auto) { 
     require_once('FirePHPCore/FirePHP.class.php'); 
     ob_start(); 

     $this->firephp = FirePHP::getInstance(true); 

     if ($auto) { 
      $this->firephp->registerErrorHandler(
         $throwErrorExceptions=false); 
      $this->firephp->registerExceptionHandler(); 
      $this->firephp->registerAssertionHandler(
         $convertAssertionErrorsToExceptions=true, 
         $throwAssertionExceptions=false); 

      /*try { 
       throw new Exception('Test Exception'); 
      } catch(Exception $e) { 
       $this->firephp->error($e); // or FB:: 
      }*/ 
     } 
    } 
} 
+0

는 PHP 구글 클라이언트를 사용하는 방법에 대한 실무 예제가 어떤 하나를 사용하는 것이 좋습니다? – MariusJP

답변

관련 문제