I am trying to access Google Analytics data for ga:visits using OAUTH 2.0 authentication. I have followed the following steps :
1.Enabled the Google Analytics API on the https://code.google.com/apis/console/ website.Also, created a client ID and saved the .p12 key
2.The generated email id was provided Read and Analyze access on Analytics website.
3.I have created a Windows form application and also downloaded the NuGet package using the package command:- Install-Package Google.Apis.Analytics.v3
4.All the references including Google.Apis,Google.Apis.Analytics.v3,Google.Apis.Auth,Google.Apis.Auth.PlatformServices,Google.Apis.Core,Google.Apis.PlatformServices are added into the project
Further, while accessing the data am facing an error :-
Locating source for c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Auth.DotNet4\OAuth2\ServiceAccountCredential.cs
This .cs file is not present at all in the downloaded package.
Any assistance would be highly appreciated.
Please find below my code -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Analytics.v3;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string keyFilePath = "C:\\Fetch GA Data-348e7435108b.p12";
string serviceAccountEmail= "xx@developer.gserviceaccount.com";
string keyPassword = "notasecret";
string websiteCode = "8482xxxx";
AnalyticsService service = null;
//loading the Key file
var certificate = new X509Certificate2(keyFilePath, keyPassword, X509KeyStorageFlags.Exportable);
//Add Scopes
var scopes =
new string[] { AnalyticsService.Scope.Analytics,AnalyticsService.Scope.AnalyticsEdit,AnalyticsService.Scope.AnalyticsManageUsers,AnalyticsService.Scope.AnalyticsReadonly
};
//create a new ServiceAccountCredential
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
//Scopes = scopes
Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }
}.FromCertificate(cert));
//Create a Service
service = new AnalyticsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential
});
DataResource.GaResource.GetRequest request = service.Data.Ga.Get(
"ga:" + websiteCode, "2015-05-27", "2015-05-27","ga:visits");
request.Dimensions = "ga:year,ga:month,ga:day";
var data = request.Execute();
}
}
I am trying to access Google Analytics data for ga:visits using OAUTH 2.0 authentication. I have followed the following steps : 1.Enabled the Google Analytics API on the https://code.google.com/apis/console/ website.Also, created a client ID and saved the .p12 key 2.The generated email id was provided Read and Analyze access on Analytics website. 3.I have created a Windows form application and also downloaded the NuGet package using the package command:- Install-Package Google.Apis.Analytics.v3 4.All the references including Google.Apis,Google.Apis.Analytics.v3,Google.Apis.Auth,Google.Apis.Auth.PlatformServices,Google.Apis.Core,Google.Apis.PlatformServices are added into the project
Further, while accessing the data am facing an error :- Locating source for c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Auth.DotNet4\OAuth2\ServiceAccountCredential.cs This .cs file is not present at all in the downloaded package. Any assistance would be highly appreciated.
Please find below my code -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Analytics.v3;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
};
}