使用.Net API查询Google大查询

时间:2015-07-10 17:20:57

标签: c# asp.net google-bigquery

我正在尝试使用c#从Google大查询中读取数据。我已经安装了nuget package ..当它到达执行查询的阶段时,它会抛出一个异常,即用户没有权限在项目上运行查询以下是我正在使用的代码示例..

public class BQObject
{
    private static Google.Apis.Bigquery.v2.BigqueryService returnService()
    {
        FileStream stream;
        UserCredential credential;

        using (stream = new FileStream(HttpContext.Current.Server.MapPath("~/client_secrets.json"), FileMode.Open, FileAccess.Read))
        {
            GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[] { BigqueryService.Scope.Bigquery },
                "user", CancellationToken.None).Result;
        }

        var Service = new BigqueryService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            //ApplicationName = "BigQueryDemoApp"
        });

        return Service;
    }

    public DataTable returnDT(string queryParam)
    {
        Google.Apis.Bigquery.v2.BigqueryService localService = returnService();
        JobsResource j = localService.Jobs;
        QueryRequest qr = new QueryRequest();
        qr.Query = queryParam;

        //at this point, it throws an exception

        QueryResponse response = j.Query(qr, "Project ID").Execute();

        //process response
    }
}

0 个答案:

没有答案