首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >替换API .NET -

替换API .NET -
EN

Stack Overflow用户
提问于 2013-07-16 14:44:37
回答 1查看 2.5K关注 0票数 1

你好,我正在尝试使用使用服务帐户的ASP.NET/C#中的3,并且似乎无法使它工作。所有内容都会编译,但是当调用GaData d=r.Execute()时,我会得到一个GoogleApiException,“参数验证对于"ids”失败了。

代码语言:javascript
运行
复制
        //This is the API url which we're storing to a string
        string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();

        //For whatever reason, this is labelled wrong. It is the email address
        //that you have added as a user to your Analytics account
        string clientId = "***********@developer.gserviceaccount.com";

        //This is the physical path to the key  file file.
        string keyFile = @"C:\key\***********.p12";

        //The password Google gives you.
        string keyPassword = "notasecret";

        //Store the authentication description
        AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;

        //Create a certificate object to use when authenticating
        X509Certificate2 key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);

        //Now, we will log in and authenticate, passing in the description
        //and key from above, then setting the accountId and scope
        AssertionFlowClient client = new AssertionFlowClient(desc, key)
        {
            ServiceAccountId = clientId,
            Scope = scope
        };

        //Finally, complete the authentication process
        //NOTE: This is the first change from the update above
        OAuth2Authenticator<AssertionFlowClient> auth =
            new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);

        //First, create a new service object
        AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });

        //Create our query
        //The Data.Ga.Get needs the parameters:
        //Analytics account id, starting with ga:
        //Start date in format YYYY-MM-DD
        //End date in format YYYY-MM-DD
        //A string specifying the metrics
        DataResource.GaResource.GetRequest r =
            gas.Data.Ga.Get("ga:nnnnnnnn", "2013-01-01", "2013-01-31", "ga:visitors");

        //Specify some addition query parameters
        r.Dimensions = "ga:pagePath";
        r.Sort = "-ga:visitors";
        r.MaxResults = 5;

        //Execute and fetch the results of our query
        GaData d = r.Execute();

1.整叠追踪

(在Google.Apis.Http.HttpClientFactory.CreateHandler(CreateHttpClientArgs args)在Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args)在c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Release\release140\default\Src\GoogleApis\Apis\Http\HttpClientFactory.cs:line ( 36 at Google.Apis.Services.BaseClientService.CreateHttpClient(Initializer初始值)( c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Release\release140 )\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:line 220 at Google.Apis.Services.BaseClientService..ctor(Initializer初始值)在c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Release\release140\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:line 182在Google.Apis.Analytics.v3.AnalyticsService..ctor(Initializer初始化)在GoogleAnalyticDotNet.Program.Main(String[] args)System.AppDomain._nExecuteAssembly(RuntimeAssembly大会的\Program.cs:line 58,在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state的System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence,String[] args),在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,Object状态,布尔preserveSyncCtx在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态,布尔preserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,preserveSyncCtx回调对象状态) at System.Threading.ThreadHelper.ThreadStart()

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-19 17:53:21

我从示例code...derp derp中删除了nnnnnnnn并离开了nnnnnnnn。用配置文件ID替换nnnnnn。-.-

DataResource.GaResource.GetRequest r= gas.Data.Ga.Get("ga:nnnnnnnn“、"2013-01-01”、"2013-01-31“、”ga:来访者“);

谢谢你的帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17679722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档