0

Firebase로 Google Bigquery를 설정하려고하는데 문제가 있습니다. 내 컴퓨터 (MacOS Sierra)에 gcloud이 설치되어 있고 프로젝트에 작곡가를 통해 Google 클라우드가 설치되어 있습니다.Bigquery가 기본 자격증 명을 얻을 수 없습니다.

내 프로젝트에 다음 코드 :

# Includes the autoloader for libraries installed with composer 
require __DIR__ . '/vendor/autoload.php'; 

# Imports the Google Cloud client library 
use Google\Cloud\BigQuery\BigQueryClient; 

# Your Google Cloud Platform project ID 
$projectId = 'hidden here only'; 

# Instantiates a client 
$bigquery = new BigQueryClient([ 
    'projectId' => $projectId 
]); 

# The name for the new dataset 
$datasetName = 'test_dataset'; 

# Creates the new dataset 
$dataset = $bigquery->createDataset($datasetName); 

echo 'Dataset ' . $dataset->id() . ' created.'; 

난 그냥 라이브러리를 통해 BigQuery를 내 데이터 집합을 만들 수있다 할 노력하고있어 모든하지만 나는 다음과 같은 오류로 인해 할 수 아니에요 :

Fatal error: Uncaught Google\Cloud\Exception\ServiceException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in /Applications/MAMP/htdocs/projects/work/bigquery-tests/vendor/google/cloud/src/RequestWrapper.php on line 219 

예제 코드에서와 같이 실행했지만 브라우저에 로그인 한 후에도 오류가 계속 발생했습니다. 어떤 도움이라도 좋을 것입니다, 고마워요!

답변

3

서비스 계정 기본 자격 증명을 설정해야합니다. putenvuseApplicationDefaultCredentials()으로 줄을 보면됩니다. https://console.cloud.google.com/iam-admin/serviceaccounts/

composer.json

{ 
    "require": { 
     "google/cloud": "^0.13.0", 
     "google/apiclient": "^2.0" 
    } 
} 

PHP 파일

# Imports the Google Cloud client library 
use Google\Cloud\BigQuery\BigQueryClient; 
use Google\Cloud\ServiceBuilder; 

$query="SELECT repository_url, 
     repository_has_downloads 
FROM [publicdata:samples.github_timeline] 
LIMIT 10"; 
$client = new Google_Client(); 
putenv('GOOGLE_APPLICATION_CREDENTIALS='.dirname(__FILE__) . '/.ssh/dummyname-7f0004z148e1.json');//this can be created with other ENV mode server side 
$client->useApplicationDefaultCredentials(); 

$builder = new ServiceBuilder([ 
       'projectId' => 'edited', 
     ]); 

     $bigQuery = $builder->bigQuery(); 

     $job = $bigQuery->runQueryAsJob($query); 
     $info=$job->info(); 
//  print_r($info); 
//  exit; 
     $queryResults = $job->queryResults(); 

     /*$queryResults = $bigQuery->runQuery(
      $query, 
      ['useLegacySql' => true]);*/ 

     if ($queryResults->isComplete()) 
     { 
      $i = 0; 
      $rows = $queryResults->rows(); 

      foreach ($rows as $row) 
      { 
       $i++; 

       $result[$i] = $row; 
      } 
     } 
     else 
     { 
      throw new Exception('The query failed to complete'); 
     } 

     print_r($result); 
: 이것은 내가 https://github.com/google/google-api-php-client 당신은 콘솔에서 서비스 계정 키 파일을 얻기 위해 필요한 라이브러리를 사용하여 한 작업 코드
+1

그렇게하기 위해서'google/apiclient' 의존성은 필요 없습니다. 'putenv' 호출은'ServiceBuilder'를 인스턴스화하기에 충분해야합니다. – jdp

+0

@ Pentium10 어떻게 키 파일을 다운로드합니까? 키를 볼 수있는 권한이 있지만 다운로드 버튼이 표시되지 않습니다. –

+0

@JoeScotto 키 파일을 다운로드하는 방법에 대한 안내는 다음 링크를 참조하십시오. https://googlecloudplatform.github.io/google-cloud-php/#/docs/v0.20.1/guides/authentication –