Skip to content

Instantly share code, notes, and snippets.

View LindaLawton's full-sized avatar
🎯
Focusing

Linda Lawton LindaLawton

🎯
Focusing
View GitHub Profile
@LindaLawton
LindaLawton / GoogleAnalyitcsServiceAccount
Created July 20, 2015 09:49
Connect to Google Analytics with a service account and the Google .net Client library
string[] scopes = new string[] {AnalyticsService.Scope.Analytics}; // view and manage your Google Analytics data
var keyFilePath = @"c:\file.p12" ; // Downloaded from https://console.developers.google.com
var serviceAccountEmail = "xx@developer.gserviceaccount.com"; // 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));
@LindaLawton
LindaLawton / GoogleAnalyticsService
Created July 20, 2015 10:23
Creates a Analytics service with either an OAuth" credential or a service account credentials
var service = new AnalyticsService(new BaseClientService.Initializer() { HttpClientInitializer = credential,
ApplicationName = "Analytics API Sample",});
@LindaLawton
LindaLawton / AnalyticsServicePublic
Created July 20, 2015 10:26
Create a Google Analytics service using a Public API key
AnalyticsService services = new AnalyticsService(new BaseClientService.Initializer()
{
ApiKey = "[API key]", // from https://console.developers.google.com (Public API access)
ApplicationName = "Analytics API Sample",
});
var services = new DriveService(new BaseClientService.Initializer(){
ApiKey = "[API key]", // from https://console.developers.google.com (Public API access)
ApplicationName = "Drive API Sample",
});
@LindaLawton
LindaLawton / Google Oauth email csharp
Created August 12, 2015 13:00
Google oauth2 email.
string _client_id = "[From Google Developer Console]";
string _client_secret = "[From Google Developer Console]";
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = _client_id, ClientSecret = _client_secret },
new string[] {"email" },
Environment.UserName ,
CancellationToken.None,
new FileDataStore("Daimto.GooglePlus.Auth.Store")).Result;
@LindaLawton
LindaLawton / WebMaster Tools API authentcation
Last active September 16, 2015 17:47
WebMaster Tools API authentcation
/// <summary>
/// Authenticate to Google Using Oauth2
/// Documentation https://developers.google.com/accounts/docs/OAuth2
/// </summary>
/// <param name="clientId">From Google Developer console https://console.developers.google.com</param>
/// <param name="clientSecret">From Google Developer console https://console.developers.google.com</param>
/// <param name="userName">A string used to identify a user.</param>
/// <returns></returns>
public static WebmastersService AuthenticateOauth(string clientId, string clientSecret, string userName)
{
@LindaLawton
LindaLawton / Wix SSIS installer
Last active October 7, 2015 09:28
Wix installer for custom ssis tasks.
<?xml version="1.0" encoding="UTF-8"?>
<Wix
xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Daimto for SSIS (SQL Server 2008)" Language="1033" Version="1.0.0.0"
Manufacturer="DAIMTO" UpgradeCode="84543418-55c4-48c0-b5be-2496fb84ffb6">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perUser"
InstallPrivileges="elevated" AdminImage="yes" />
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
@LindaLawton
LindaLawton / GetAuthURI
Last active October 19, 2015 07:40
Creates the auth url
/// <summary>
/// Creates the auth url
/// https://accounts.google.com/o/oauth2/auth?client_id={clientid}&amp;redirect_uri=urn:ietf:wg:oauth:2.0:oob&amp;scope={scope}&amp;response_type=code
/// client id from google developer console.
/// scope comma seproated
/// </summary>
/// <returns></returns>
public static Uri GetAuthURI()
{
return new Uri(string.Format("https://accounts.google.com/o/oauth2/auth?client_id={0}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope={1}&response_type=code", Properties.Resources.clientId, Properties.Resources.scope));
private void auth()
{
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(GetTitle);
webBrowser1.Navigate(SimpleAuth.GetAuthURI().ToString());
}
/// <summary>
@LindaLawton
LindaLawton / getAcccessToken
Last active October 19, 2015 07:54
takes a refreshtoken and exchanges it for an accessotken.
class AccessTokenResponse
{
public string access_token { get; set; }
public string token_type { get; set; }
public string expires_in { get; set; }
}
/// <summary>
/// takes a refreshtoken and exchanges it for an accessotken.
/// </summary>