2017-04-18 55 views
0

有没有在Azure函数中使用Google.Cloud.BigQuery.V2(1.0.0-beta10)API的方法?在Azure函数中使用Google.Cloud.BigQuery.V2 API

我喜欢使用这个API和Azure的功能我的C#代码,但得到这个错误:

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. 

在我project.json我有以下代码:

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

我觉得API在.NET 4.5和Azure函数需要4.6。所以似乎没有办法在自动对焦中使用这个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服务帐户的关键。通常情况下,我想,我可以访问我的BigQuery表格通过知道像这样的项目,并dadaset的ID在我的C#代码:

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

var client = BigQueryClient.Create(projectId); 

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

包的目标是罚款和net46会工作。你能分享你的代码吗?你看到包恢复过程发生了吗?你是否偶然部署了project.lock.json文件? –

+0

感谢您的评论。我不知道为什么,但几分钟后它没有发生这些错误。编译成功。但是我的功能仍然不起作用,因为缺少证书。我会更新我的问题。 – Mogry

回答

0

就像之前提到的,可以使用Google.Cloud.BigQuery.V2( 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文件(谷歌云平台 - > 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);