GithubHelp home page GithubHelp logo

google-apis's Introduction

Google APIs for Xamarin

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

costo avatar ermau avatar therzok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-apis's Issues

Google signin crashing on phone but works on simulator

My SignIn method is as follows:

 public void SignIn()
 {
     Debug.WriteLine("In SignIn");
     if (GdAuthenticator == null)
     {
         (App.GdClientId, App.GdRedirectUrl, App.GdClientSecret) = App.SetIDs4GoogleDrive();
         Debug.WriteLine($"GdRedirectUrl: {App.GdRedirectUrl}");
         GdAuthenticator = new OAuth2Authenticator(
             App.GdClientId,
             App.GdClientSecret,
             App.GdScope,
             new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
             new Uri(App.GdRedirectUrl),
             new Uri("https://www.googleapis.com/oauth2/v4/token"),
             isUsingNativeUI: true);
         GdAuthenticator.Completed += Auth_Completed;
         AuthenticatorHelper.OAuth2Authenticator = GdAuthenticator;
     }
     // This flag is set here as for iOS, AppDelegate.OpenUrl is invoked even before
     //    this.Auth_Completed event is invoked and this flag is needed to redirect
     //    to this app after authentication
     if (Device.RuntimePlatform == Device.iOS)
         App.StorageServiceSignedIn = App.StorageServices.GoogleDrive;
     OAuthLoginPresenter presenter = new OAuthLoginPresenter();
     presenter.Login(GdAuthenticator);
 }

GdScope is set as follows:

public static string GdScope = "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file";

The error occuring is:

System.UnauthorizedAccessException
Message=Access to the path '/private/var/mobile/Containers/Data/Application/FE509305-6324-4705-B517-DA2A98B18A69/.local/share/google-filedatastore/Google.Apis.Auth' is denied.

I don't find any line containing "FE5" in the device logs.

The Publishing Status of my app on Google API site is "Testing".

Since it is not failing on the simulator I assume that all authentications are in order. The app is run on iPhone 6 in Debug mode.

I published the app to App Store after testing in Debug mode but never tested on device in Release mode. But I found the issue after users facing crash issue while signing into Google Drive services that I am using in the app.

Let me know if you need any further info.

ThanQ...

Token expired

How i can refresh the token when expired? I want to show the login UI only the first time the user access.

the call is ambiguous between the following methods

untitled

my solution if is ok:

var attributes = property.GetCustomAttributes<Google.Apis.Util.RequestParameterAttribute>();            
                if (attributes != null && attributes.Count() > 0)
                {
                    var attribute = attributes.ElementAt (0);
                    string name = attribute.Name ?? property.Name.ToLower();
                    object valueObject = property.GetValue(this, new object[] {} );
                    string value = String.Empty;
                    if (valueObject != null)
                    {
                        value = valueObject.ToString();
                    }

                    requestBuilder.AddParameter(attribute.Type, name, value);
                }

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.