title: How to use Google Analytics API with 2-legged OAuth (Google Apps for business)?
body: <p>I want to develop an application for the business I work. We are using Google Apps and want to get data from Google Analytics and show it in one of our web apps. I do not want the client to see any request to authorize the app. I want to use 2-legged OAuth like such <a href="http://www.google.com/support/a/bin/answer.py?hl=en&amp;answer=162105" rel="nofollow">http://www.google.com/support/a/bin/answer.py?hl=en&amp;answer=162105</a> but Google Analytics is not in the list. Will I still be able to use it ? Is it supported in the <a href="http://code.google.com/p/google-gdata/" rel="nofollow">.NET Google Data API library</a> or the <a href="http://code.google.com/p/google-api-dotnet-client/" rel="nofollow">Google API .NET Client</a> ?</p>
  
  <p><em><strong>EDIT 1</em></strong> : </p>
  
  <p>Using the <a href="http://code.google.com/p/google-api-dotnet-client/" rel="nofollow">Google API .NET Client</a>, I came up with something that should work to my sense : </p>
  
  <pre><code>var auth = new Google.Apis.Authentication.OAuth2LeggedAuthenticator(DOMAIN_CONSUMER_KEY, DOMAIN_CONSUMER_SECRET, USER_TO_IMPERSONATE, DOMAIN);
  
  var service = new Google.Apis.Analytics.v3.AnalyticsService(auth);
  
  service.Key = DEV_KEY_FROM_API_CONSOLE;
  
  var _request = service.Management.Accounts.List();
  
  foreach (var item in _request.Fetch().Items)
  {
      Console.WriteLine(item.Name);
  }
  </code></pre>
  
  <p>... but I get this error : </p>
  
  <pre><code>Google.Apis.Requests.RequestError 
  InvalidCredentials [401]
  Errors [
      Message[Invalid Credentials] 
      Location[Authorization - header] 
      Reason[authError] 
      Domain[global]
      ]
  </code></pre>
  
  <p>Thanks</p>