Giter Club home page Giter Club logo

google-apis's Introduction

Google APIs for Xamrin

Quickly add access to Google's APIs to your Mono for Android app!

To get started with the Google APIs, you'll need to register your app as a web application and obtain your client ID at the Google API Console.

A set of generated APIs are included, but additional or newer versions of the APIs may be available at Google API .NET client WIKI.

Before you can access the APIs, the user will need to login to Google. You'll need to supply your Client ID, the redirect URI you supplied to Google, and the scopes you're requesting. Each API has a set of scopes that will enable you to access certain functionality.

var auth = new Google.Apis.Authentication.OAuth2.GoogleAuthenticator (ClientID,
				new Uri ("http://example.com/callback"),
				Google.Apis.Tasks.v1.TasksService.Scopes.Tasks.GetStringValue());

// When we're authenticated, we'll show the tasks from the default list
Action showTasks = () =>
{
	var service = new Google.Apis.Tasks.v1.TasksService (auth);

	// get the tasks from the default task list
	var tasks = service.Tasks.List("@default").Fetch();
	foreach (var task in tasks.Items)
		Console.WriteLine (task.Title);
};

// We don't want to have to login every time, so we'll use the Xamarin.Auth AccountStore
AccountStore store = AccountStore.Create (this);
Account savedAccount = store.FindAccountsForService ("google").FirstOrDefault();
if (savedAccount != null)
{
	this.auth.Account = savedAccount;
	showTasks();
}
else
{
	this.auth.Completed += (sender, args) =>
	{
		if (args.IsAuthenticated)
		{
			// Save the account for the future
			store.Save (args.Account, "google");
			RunOnUiThread (showTasks);
		}
		else // Authentication failed
			Toast.MakeText (this, "Error logging in", ToastLength.Long).Show();
	};

	Intent authIntent = this.auth.GetUI (this);
	StartActivity (authIntent);
}

Intent loginIntent = auth.GetUI (this);
StartActivity (loginIntent);

google-apis's People

Contributors

ermau avatar

Watchers

James Cloos avatar Matthew Leibowitz avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.