2017-04-18 1 views
0

Azure 함수에서 Google.Cloud.BigQuery.V2 (1.0.0-beta10) API를 사용하는 방법이 있습니까? 내 project.json에서Azure 함수에서 Google.Cloud.BigQuery.V2 API 사용

error CS0103: The name 'BigQueryClient' does not exist in the current context 
error CS0246: The type or namespace name 'BigQueryTable' could not be found (are you missing a using directive or an assembly reference?) 
error CS0246: The type or namespace name 'BigQueryJob' could not be found (are you missing a using directive or an assembly reference?) 
error CS0246: The type or namespace name 'CreateQueryJobOptions' could not be found (are you missing a using directive or an assembly reference?) 
error CS0246: The type or namespace name 'BigQueryResults' could not be found (are you missing a using directive or an assembly reference?) 
error CS0246: The type or namespace name 'GetQueryResultsOptions' could not be found (are you missing a using directive or an assembly reference?) 
Compilation failed. 

나는 다음과 같은 코드가 있습니다 : 나는를

{ 
    "frameworks": { 
    "net46":{ 
     "dependencies": { 
     "Google.Cloud.BigQuery.V2": "1.0.0-beta10" 
     } 
    } 
    } 
} 

생각

나는이 API와 푸른 함수 내 C# 코드를 사용하지만이 오류가 좋아 API는 .NET 버전 4.5이고 Azure 함수는 4.6이 필요합니다. 따라서 AF에서이 API를 사용할 수있는 방법이없는 것 같습니다. "net45"로 시도했지만 동일한 오류가 발생합니다.

업데이트 :이 API는 AF에서 작동합니다 (아래 설명 참조). 편집이 완료되었습니다. 하지만 내 기능은 누락 된 자격 증명 때문에 여전히 작동하지 않습니다. 내 Visual Studio에서 코드를 실행하고해야처럼 작동하지만, AF에서 나는 다음과 같은 오류가 발생했습니다 :

Exception while executing function: Functions.TimerTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. Google.Api.Gax: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information. 

은 이미 JSON은 내 AF에 업로드 파일로 서비스 계정 키를 생성합니다. 이 Google.Cloud.BigQuery.V2을 (사용할 수 있습니다 전에

string projectId = "..."; 
string datasetId = "..."; 

var client = BigQueryClient.Create(projectId); 

List<BigQueryTable> tables = client.ListTables(datasetId).ToList(); 
+0

패키지 대상이 괜찮 및 net46에 작동합니다. 코드를 공유 할 수 있습니까? 패키지 복원 프로세스가 진행되고 있습니까? 우연히 project.lock.json 파일을 배포하고 있습니까? –

+0

의견을 보내 주셔서 감사합니다. 왜 그런지 모르지만 몇 분 후에는 이러한 오류없이 작동했습니다. 편집이 완료되었습니다. 하지만 자격 증명이 없어서 내 기능이 작동하지 않습니다. 나는 내 질문을 업데이트 할 것이다. – Mogry

답변

0

같이 언급 : 일반적으로, 내 생각, 내 C# 코드에서이 같은 프로젝트와 dadaset ID를 알고 통해 BigQuery를 내 테이블에 액세스 할 수 1.0.0-beta10) Azure 함수의 API. 위의 코드를 사용하십시오. 하나 이상의 종속성을 사용하려면 쉼표로 구분하여 추가하십시오. 제 경우에는 Google.Apis도 필요했습니다. 코드는 다음과 같습니다

{ 
"frameworks": { 
    "net46":{ 
     "dependencies": { 
     "Google.Cloud.BigQuery.V2": "1.0.0-beta10", 
     "Google.Apis": "1.24.1.0" 
     } 
    } 
    } 
} 

을위한 인증의 경우는 JSON 파일 (Google 클라우드 플랫폼 -> API 관리자 -> 자격 증명)와 같은 서비스 계정 키를 생성하는 것이 중요하다. Azure 기능에서 플랫폼 기능 -> 응용 프로그램 설정 -> 응용 프로그램 설정으로 이동하십시오. 새 키 (예 : 'GoogleCloudKey')를 입력하고 JSON 파일의 내용을 셀 값으로 복사합니다. "run.csx"에서

당신은 자격 증명을 통해 만들어 손에 있습니다

GoogleCredential credential = null; 

using (var credentialStream = new MemoryStream(Encoding.UTF8.GetBytes(ConfigurationManager.AppSettings["GoogleCloudKey"]))) 
{ 
credential = GoogleCredential.FromStream(credentialStream); 
} 

var client = BigQueryClient.Create(projectId, credential); 
관련 문제