提出请求时DoubleClick搜索API 403错误


private async Task Run()
    {
        //setting up OAuth 2.0 authentication
        ClientSecrets secret = new ClientSecrets
        {
            ClientId = <My ID Here>,
            ClientSecret = <My Secret Here>
        };
        UserCredential credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(secret, new[] { Scope }, "user", CancellationToken.None);
        //create the service
        service = new DoubleclicksearchService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentials,
            ApplicationName = <My Application Name Here>
        });
        //make request to download keywords; response variable will hold Id of generated report
        Report response = await service.Reports.Request(CreateRequestBody()).ExecuteAsync();
        Console.WriteLine("Created Report: ID={0}", response.Id);
    }

DoubleClick搜索API的首次用户。以上代码是我的摘要试图做出关键字报告请求。但是,每次运行,service.reports.request Line都会引发异常。具体的错误是:

"Google.Apis.Requests.RequestErrorrnForbidden [403]rnErrors [rntMessage[Forbidden] Location[ - ] Reason[forbidden] Domain[global]rn]rn"

有什么想法在这里发生了什么?如果我在没有executeasync()部分的情况下拨打电话,则可以正常工作,但是我无法获得提交报告的ID。

对于那些有兴趣的人,似乎在此使用的方法是错误的。我相信,收集包含正在生成的报告的ID的报告对象的检索不是异步创建的。当我将最后一个代码更改为

//make request to download keywords; response variable will hold Id of report to be generated
var request = service.Reports.Request(CreateRequestBody());
response = request.Execute();
Console.WriteLine("Report being generated.  Report ID: {0}", response.Id);

它正常工作。

相关内容

  • 没有找到相关文章

最新更新