.net Google analytics v3 Google.API.Requests.RequestError用户没有任何Google analytics帐户。[403]

.net Google analytics v3 Google.API.Requests.RequestError用户没有任何Google analytics帐户。[403],.net,google-analytics,google-analytics-api,.net,Google Analytics,Google Analytics Api,我正在使用google analytics v3 api来自动报告google analytics数据 string scope_url = "https://www.googleapis.com/auth/analytics.readonly"; string client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com"; string key_file = @"xxxxxxxxxxxxxxxxxxxxxxxx

我正在使用google analytics v3 api来自动报告google analytics数据

string scope_url = "https://www.googleapis.com/auth/analytics.readonly";
string client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com";
string key_file = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12";
string key_pass = "notasecret";
AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;
//key: Load up and decrypt the key
X509Certificate2 key = new X509Certificate2(key_file, key_pass, X509KeyStorageFlags.Exportable);
//client: we're using the AssertionFlowClient, because we're logging in with our certificate
AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = client_id, Scope = scope_url };
OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
//gas: An instance of the AnalyticsService we can query
// AnalyticsService gas = null;// new AnalyticsService(auth);//not compile
var gas = new AnalyticsService(new BaseClientService.Initializer()
       {
                    Authenticator = auth
       });
//r: Creating our query
DataResource.GaResource.GetRequest r = gas.Data.Ga.Get("ga:xxxxxxxx", "2012-09-26", "2012-10-10", "ga:visitors");
//d: Execute and fetch the results of our query
GaData d = r.Fetch();
字符串范围\u url=”https://www.googleapis.com/auth/analytics.readonly";
字符串客户端\u id=”xxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com";
字符串key_file=@“xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12”;
字符串密钥\u pass=“notasecret”;
AuthorizationServerDescription desc=GoogleAuthenticationServer.Description;
//密钥:加载并解密密钥
X509Certificate2 key=新的X509Certificate2(key_文件,key_通行证,X509KeyStrageFlags.Exportable);
//客户端:我们正在使用AssertionFlowClient,因为我们正在使用证书登录
AssertionFlowClient客户端=新的AssertionFlowClient(desc,key){ServiceAccountId=client_id,Scope=Scope_url};
OAuth2Authenticator auth=新的OAuth2Authenticator(客户端,AssertionFlowClient.GetState);
//gas:我们可以查询的AnalyticsService实例
//分析服务气体=零;//新分析服务(auth)//不编译
var gas=新的分析服务(新的BaseClientService.Initializer()
{
验证器=auth
});
//r:创建我们的查询
DataResource.GaResource.GetRequest r=gas.Data.Ga.Get(“Ga:xxxxxxxx”、“2012-09-26”、“2012-10-10”、“Ga:visitors”);
//d:执行并获取查询结果
GaData d=r.Fetch();
我收到错误
Google.api.Requests.RequestError用户没有任何Google Analytics帐户。[403]错误[消息[用户没有任何Google Analytics帐户。]位置[-]原因[权限不足]域[全局]]

使用相同的帐户时,我已经使用v2.4版本实现简单的api访问它正在工作。 不知道为什么它适用于v2.4版本,而不适用于分析api的v3版本


在google api控制台中,我已将Analytics api和google api service service设置为on(打开)

在从google分析界面添加电子邮件ID[上述代码中的客户端ID]后,我能够提取数据。
关于一个google analytics注册的详细信息,请参见链接

Infact。我有两个帐户正在为两个不同的网站获取数据。我必须将该电子邮件帐户注册到这两个帐户