rishuk51 / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

Issue faced while accessing GA data - Code trying to find ServiceAccountCredential.cs file #702

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Name of affected component: Core Reporting API

Name of related library and version, if applicable (e.g. Java, Python,
HTTP, Objective-C, etc.): C# . Net

Issue summary:
I am trying to access Google Analytics data for ga:visits and ga:transactions 
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.PlatformS
ervices,Google.Apis.Core,Google.Apis.PlatformServices are added into the 
project 

Error faced :- Locating source for 
c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bi
n\Debug\test\default\Src\GoogleApis.Auth.DotNet4\OAuth2\ServiceAccountCredential
.cs

Expected output:
Able to view Google Analytics data

Actual results:
Get the visits and transactions happening during the day

Notes:
Please provide your assistance on the issue.
Please find below my code used:-

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();   

            }

        }
}

Original issue reported on code.google.com by ananthra...@colehaan.com on 15 Jul 2015 at 1:18

GoogleCodeExporter commented 8 years ago
Could anyone please guide me with the above issue.

Original comment by ananthra...@gmail.com on 21 Jul 2015 at 5:31