DoubleClick Search API 403发出请求时出错

时间:2014-01-29 20:19:55

标签: google-api

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 Search API的首次使用者。上面的代码是我尝试发出关键字报告请求的代码段。但是,每次运行时,service.Reports.Request行都会抛出异常。特别是错误是:

"Google.Apis.Requests.RequestError\r\nForbidden [403]\r\nErrors [\r\n\tMessage[Forbidden] Location[ - ] Reason[forbidden] Domain[global]\r\n]\r\n"

有什么想法在这里发生了什么?如果我在没有ExecuteAsync()部分的情况下进行调用,它可以正常工作,但是我无法获得提交报告的ID。

1 个答案:

答案 0 :(得分:0)

对于那些感兴趣的人,看来ExecuteAsync在这里使用是错误的方法。我相信,检索包含正在生成的报告的ID的Report对象不是异步创建的。当我将最后一段代码更改为

//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);

它按预期工作。