错误:“invalid_grant”,说明:“”,Uri:“”使用本地计算机上的服务帐户

时间:2015-09-11 07:10:19

标签: google-oauth

我在使用本地计算机上的服务帐户时出现以下错误

错误:

  

invalid_grant“,描述:”“,Uri:”“。

请参阅以下代码 -

 string[] scopes = new string[] {
    AnalyticsService.Scope.Analytics
 }; // view and manage your Google Analytics data

 var keyFilePath = @
 "c:\xxxxxxx.p12"; // Downloaded from https://console.developers.google.com
 var serviceAccountEmail = "xxxxx@developer.gserviceaccount.com"; // found https://console.developers.google.com

 //loading the Key file
 var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
 var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail) {
    Scopes = scopes
 }.FromCertificate(certificate));

 var service = new AnalyticsService(new BaseClientService.Initializer() {
    HttpClientInitializer = credential,
    ApplicationName = "Analytics API Sample",
 });
 string profileId = "xxxxxx";
 DataResource.RealtimeResource.GetRequest request = service.Data.Realtime.Get(String.Format("ga:{0}", profileId), "rt:activeUsers");
 RealtimeData feed = request.Execute();

0 个答案:

没有答案
相关问题