【发布时间】:2016-07-02 04:47:20
【问题描述】:
我正在尝试使用 Double Click for Advertisers API (DFA)。我已经探索了“Try it”并通过谷歌开发者控制台测试了 Api,它按预期工作。我能够捕获授权令牌并执行获取和发布请求(通过浏览器和编程方式)。 但是,当我尝试使用 donet api 2.4 以编程方式执行完全相同的操作时,生成的身份验证令牌不允许我执行任何请求,它总是返回 HTTP 400 错误请求,原因是 Invalid ProfileID。
我不确定 client_secrets.json 是否正确,但我是使用有权访问报告的同一电子邮件帐户创建的。
{
"installed": {
"client_id": "<client_id>.apps.googleusercontent.com",
"project_id": "<project_id>",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "<secret>",
"redirect_uris": [ "urn:ietf:wg:oauth:2.0:oob", "http://localhost" ]
}
}
我使用了下面的凭据代码:
private static readonly IEnumerable<string> scopes = new[] {
DfareportingService.Scope.Dfareporting,
DfareportingService.Scope.Dfatrafficking
};
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"dfa-user", CancellationToken.None,
new FileDataStore("DfaReporting.Samples")).Result;
生成的令牌为我提供以下信息:
{
"issued_to": "<client_id>.apps.googleusercontent.com",
"audience": "<client_id>.apps.googleusercontent.com",
"scope": "https://www.googleapis.com/auth/dfareporting https://www.googleapis.com/auth/dfatrafficking",
"expires_in": 3073,
"access_type": "offline"
}
我上面提到的库可以在 GitHub 上找到:https://github.com/googleads/googleads-dfa-reporting-samples/tree/master/dotnet/v2.4
我错过了什么?
【问题讨论】:
-
失败的请求在哪里?您只发布了您的身份验证代码,这不足以找到您的错误。请记住,进行身份验证的用户必须与拥有您尝试为其请求数据的个人资料的用户相同。
-
它没有完整的代码,但基本上服务是我获取凭据的方法的结果。给出异常(错误请求)的请求是 service.Reports.Run
DfareportingService service = DfaReportingFactory.getInstance(); (...) // Run the report. File file = service.Reports.Run(profileId, reportId).Execute() -
首先执行 userprofiles.list 您尝试为用户无权访问的配置文件生成报告。
标签: c# .net google-api google-oauth google-api-dotnet-client