xamarinxamarin.ios-binding

How can I use Google's people API in Xamarin.iOS?


I have to access Google contacts in our Xamarin. ios app so, We have generated Google's people API key and client id in Google developer portal But I don’t know how to consume API in Xamarin.ios app. We need to get Google contact details using API. We got some code for .net in Google documentation but unfortunately, it’s not working in Xamarin.ios platform. DLL not supported in xamarin platform. Please help me to solve this issue.


Solution

  • I have solved it by using Xamarin.Auth library.

    Auth = new OAuth2Authenticator(
                 Configuration.ClientId,
                 string.Empty,
                 "https://www.googleapis.com/auth/contacts",
                 new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
                 new Uri(Configuration.RedirectUrl),
                 new Uri("https://www.googleapis.com/oauth2/v4/token"),
                 isUsingNativeUI: true);
    
                var viewController = Auth.GetUI();
                PresentViewController(viewController, true, null);
    
                Auth.Completed += Auth_Completed;
                Auth.Error += Auth_Error;
    
    
    
     private void Auth_Error(object sender, AuthenticatorErrorEventArgs e)
            {
    
            }
    
    
    
     private  void  Auth_Completed(object sender, AuthenticatorCompletedEventArgs e)
            {
    
                // SFSafariViewController doesn't dismiss itself
                DismissViewController(true, null);
    
                if (e.IsAuthenticated)
                {
                }
         }
    

    Must implement OpentUrl() in Appdelegate.cs calss upto iOS 12 and above iOS 13 implement OpenUrlContexts() method in SceneDelegate.cs