C# Google DFA报告-错误请求(400)无效ProfileID

C# Google DFA报告-错误请求(400)无效ProfileID,c#,.net,google-api,google-oauth,google-api-dotnet-client,C#,.net,Google Api,Google Oauth,Google Api Dotnet Client,我试图使用双击广告API(DFA)。我已经探索了“试试它”,并通过google开发者控制台测试了Api,它按照预期工作。我能够捕获授权令牌并执行get和post请求(通过浏览器和编程)。 但是,当我尝试以编程方式使用donet api 2.4执行完全相同的操作时,生成的身份验证令牌不允许我执行任何请求,它总是返回HTTP 400错误请求,原因是ProfileID无效。 我不确定client_secrets.json是否正确,但我是使用访问报告的同一电子邮件帐户创建的 { "installed

我试图使用双击广告API(DFA)。我已经探索了“试试它”,并通过google开发者控制台测试了Api,它按照预期工作。我能够捕获授权令牌并执行get和post请求(通过浏览器和编程)。 但是,当我尝试以编程方式使用donet api 2.4执行完全相同的操作时,生成的身份验证令牌不允许我执行任何请求,它总是返回HTTP 400错误请求,原因是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" ]
  }
}
{
“已安装”:{
“客户端id”:“.apps.googleusercontent.com”,
“项目id”:“,
“auth_uri”:https://accounts.google.com/o/oauth2/auth",
“令牌uri”:https://accounts.google.com/o/oauth2/token",
“身份验证提供程序\u x509\u证书\u url”:https://www.googleapis.com/oauth2/v1/certs",
“客户机密”:“,
“重定向URI”:[“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;
private static readonly IEnumerable scopes=new[]{
DfareportingService.Scope.Dfareporting,
DfareportingService.Scope.dfatraffick
};    
凭证=GoogleWebAuthorizationBroker.AuthorizationAsync(
GoogleClientSecrets.Load(stream.Secrets),
范围,
“dfa用户”,取消令牌。无,
新文件数据存储(“DfaReporting.Samples”))。结果;
生成的令牌为我提供了以下信息:

{
 "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"
}
{
“发布至”:“.apps.googleusercontent.com”,
“受众”:“.apps.googleusercontent.com”,
“范围”:https://www.googleapis.com/auth/dfareporting https://www.googleapis.com/auth/dfatrafficking",
“expires_in”:3073,
“访问类型”:“脱机”
}
我上面提到的库可以在GitHub上找到:


我错过了什么

首先确保您已经设置了此选项

  • 您必须拥有DCM帐户。有关注册信息,请参阅
  • 必须启用DCM帐户才能访问API。请与DoubleClick代表或DCM支持团队联系以获得帮助。(dcm)-support@google.com)
  • 您必须具有访问此帐户的用户配置文件。让DCM帐户管理员创建与此帐户关联的用户配置文件
  • 在我看来,您尝试使用谁进行身份验证都无法访问您尝试请求的配置文件

    回应评论:

    如果您使用的是.net客户端库,我不明白您为什么会在评论时手动调用以下请求

    https://www.googleapis.com/dfareporting/v2.4/userprofiles?access_token=<access token> 
    
    如果发送的配置文件id无效,则可能返回无效的配置文件id

    service.UserProfiles.Get(profileId).Execute();
    
    运行报告

    为了能够运行报告,用户必须能够访问配置文件和报告。您的错误消息意味着用户没有访问该配置文件的权限。您需要使用具有访问权限的用户登录或授予该用户访问权限

    service.Reports.Run(profileId,reportId).Execute();
    

    失败的请求在哪里?您只发布了身份验证代码,这还不足以找到您的错误。请记住,进行身份验证的用户必须与您试图请求数据的配置文件的所有者相同。它没有完整的代码,但基本上服务是我获取凭据的方法的结果。发出异常(错误请求)的请求是service.Reports.Run
    DfareportingService=DfaReportingFactory.getInstance();(…)//运行报告。File File=service.Reports.Run(profileId,reportId).Execute()
    do userprofiles.list首先尝试为用户无权访问的配置文件运行报告。通过设置GET>I,获得了一个空的配置文件列表,这意味着传递给client_secrets.json的凭据没有正确链接到我正在使用的DFA帐户。我如何知道我正确设置了客户机密?我已经按照文档中的说明进行了操作。创建了一个项目,启用了API并创建了一个秘密。不,您的配置文件列表为空,因为用户没有任何配置文件。如果凭据不正确,则会出现错误,根本无法调用API。至于正确设置,请检查nr 2和nr 3。确保你有访问权限。我将检查你的提示,稍后编辑我的评论。另外,为了回答为什么我要手动测试它,我还需要对我的令牌是否有效进行故障排除,因为使用dotnetapi,我只收到了错误的请求。
    service.UserProfiles.List().Execute()给出0个结果。在我的问题中,我没有将profileID和ReportID放在代码示例中,但我有它,它们与我在Web上的“trytapi”上测试时使用的相同。摘要看起来我的用户没有配置文件。那我是怎么得到它们的?我用来登录DFA Backoffice的电子邮件帐户和我用来在开发者控制台中创建项目、客户机密和启用api的电子邮件帐户是一样的。我一点也不明白这些档案是怎么工作的。
    
    service.Reports.Run(profileId,reportId).Execute();