2013-05-07 185 views
0

我正在使用谷歌分析v3 api的谷歌分析数据报告的一些自动化。Google analytics v3 Google.Apis.Requests.RequestError用户没有任何Google Analytics帐户。 [403]

string scope_url = "https://www.googleapis.com/auth/analytics.readonly"; 
string client_id = "[email protected]"; 
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(); 

我收到错误Google.Apis.Requests.RequestError User does not have any Google Analytics account. [403] Errors [ Message[User does not have any Google Analytics account.] Location[ - ] Reason[insufficientPermissions] Domain[global]]

相同的帐户时,我必须通过简单的API访问它正在使用V2.4版本的实现。 不知道它为什么适用于v2.4版本,而不适用于v3版本的analytics api。

在谷歌API控制台I已置分析API和谷歌API服务的服务为上

回答

相关问题