Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用.NETAPI查询Google大查询_C#_Asp.net_Google Bigquery - Fatal编程技术网

C# 使用.NETAPI查询Google大查询

C# 使用.NETAPI查询Google大查询,c#,asp.net,google-bigquery,C#,Asp.net,Google Bigquery,我正在尝试使用c从Google big query读取数据。我已经安装了nuget软件包。当它到达执行查询的阶段时,它会抛出一个异常,即用户无权对项目运行查询。下面是我正在使用的代码示例 public class BQObject { private static Google.Apis.Bigquery.v2.BigqueryService returnService() { FileStream stream; UserCredential c

我正在尝试使用c从Google big query读取数据。我已经安装了nuget软件包。当它到达执行查询的阶段时,它会抛出一个异常,即用户无权对项目运行查询。下面是我正在使用的代码示例

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
    }
}

我从您的示例中删除了额外的代码位,以便将其缩小到异常发生的位置。对吗?提供异常的确切消息/类型可能会有所帮助。请确保运行作业的用户是运行作业的项目的成员。@MichaelSheldon感谢您的建议。。你能再解释一下吗。。。服务提供商已经向我提供了Client_Secret.Json文件和项目Id,我该怎么做