我试图从google analytics api检索数据,这是我的课程
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Google.Apis.Analytics.v3;
using Google.Apis.Auth.OAuth2;
using System.Threading;
using Google.Apis.Util.Store;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Services;
namespace zirfoon.model
{
public class googleanalyze
{
public static void main(){
string[] scopes = new string[] { AnalyticsService.Scope.Analytics,AnalyticsService.Scope.AnalyticsManageUsers }; // view and manage your Google Analytics data
var keyFilePath = HttpContext.Current.Server.MapPath("/loominexMvc-f104810a4caa.p12"); // Downloaded from https://console.developers.google.com
var serviceAccountEmail = "[email protected]"; // 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 credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes =scopes
}.FromCertificate(certificate));
Visual Studio调试器打开一个窗口以供选择,ServiceCredential.cs
但它不存在,我更改了作用域,但仍然一无所有...我已经正确创建了我的api帐户,并且所有信息(例如serviceAccountEmail
和)keyFilePath
都是正确的,但仍然出现错误
我发现问题仅在于调试模式当我在没有调试器的情况下运行项目时,没有任何问题...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句