title: Google calendar Api v3 and OAuth2 ServiceAccountCredential in asp.net
body: <p>I´m trying to connect to Googels API using the Service Account Credential. I have created a Service Account in the Googles developers console I also have done all the settings in the Google Apps domain account, but it does not work. When I try to get an event in my Google calender I just get the following message. Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error: "access_denied" Description: "Requested Client Not Authorized." Uri: ""</p>
  
  <p>Please, what am I doing wrong?</p>
  
  <p>This is my code.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.IO;
  using System.Security.Cryptography.X509Certificates;
  using Google.Apis.Auth.OAuth2;
  using Google.Apis.Util.Store;
  using Google.Apis.Services;
  using Google.Apis.Calendar.v3;
  using Google.Apis.Calendar.v3.Data;
  
  public partial class Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          string serviceAccountEmail = ".....@developer.gserviceaccount.com";
          string keyFilePath = @"c:\nameName.p12";
          string  userEmail = "name.name@domain.com";
          string[] scopes = new string[] { CalendarService.Scope.Calendar, CalendarService.Scope.CalendarReadonly }; 
  
          var certificate = new X509Certificate2(keyFilePath, "secret", X--------509rageFlags&amp;???.Exportable);
          var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
          {
              User = userEmail,
              Scopes = scopes
          }.FromCertificate(certificate));
  
          // Create the service.
          var calService = new CalendarService(new BaseClientService.Initializer()
          {
              ApplicationName = "Test calendar",
              HttpClientInitializer = credential,
          });
  
          string eventid = "_60q30c1g60o0s46chk74oj0dhh64rj8ca16p138dpo74ojedhh8oq34dq4";
  
          Event myEvent = calService.Events.Get(userEmail, eventid).Execute();
          Literal1.Text = myEvent.Summary;
  
      }
  }
  </code></pre>