Need to sync google drive with my xamarin forms application.

I need to sync my xamarin forms application with google drive.
I'm new in xamarin forms.
Please help asap

Posts

  • Take a look a this video, is not directly dedicated to Google Drive files but is nearly

    This is the Drive documentation for mobile developers
    https://developers.google.com/drive/

  • ComquackComquack Member ✭✭

    Hi, I'm am also facing a similar problem and am also new to to xamarin
    I am trying to implement a feature in my app where the User can upload the excel files created by the app to their Google Drive,
    I tried following the example here stackoverflow.com/questions/38432491/google-drive-api-implementation-xamarin-android and I can get the user to sign on or connecting to the drive to work, but I can not figure out how to make it request a sign in and then upload.

    It seems to be grabbing the google sign in details from some where but is does not explicitly request a sign in.

    This is the setup for the client, it works for the drive like this and works for signing in when //.AddApi(Auth.GOOGLE_SIGN_IN_API,gso) is uncommented and the add scope is removed
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
    .RequestEmail()
    .RequestScopes(new Scope(Constants.scopes))
    .Build();

            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    //.AddApi(Auth.GOOGLE_SIGN_IN_API,gso)
                    .AddApi(DriveClass.API)
                   .AddScope(DriveClass.ScopeFile)
                  .AddOnConnectionFailedListener(OnConnectionFailed)
                    .Build();
    

    I hope some of this is useful.

  • Gandhi_123Gandhi_123 Member ✭✭

    Hello @Comquack, thank you for taking interest in my problem. I referred your shared link of stackoverflow but there is a code related to xamarin android app and I'm working on Xamarin forms. I'm not doing any code in Xamarin.droid project. I'm just redirect my flow from MyActivity.cs of xamarin.droid project to App.xaml using these below line of code.

    ==>MyActivity.cs file

           protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
    
            base.OnCreate(bundle);
    
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }
    
  • ComquackComquack Member ✭✭

    My Project is also in Xamarin.Forms, but I couldn't find a solution that worked. So for my code I am implementing separate procedures for Android and IOS. The Xamarin.Auth Library seems to be built for using a single implementation, but I couldn't get it to give me the credentials to use Drive. The non android specific method I tried was
    /developers.google.com/drive/api/v3/quickstart/dotnet. It maywork better for you than it did for me.

  • ComquackComquack Member ✭✭

    This is my attempt at a generic login. It worked for logging in, but I couldn't get the credentials to work for google drive.

    void OnLoginClicked()
    {
    string clientId = null;
    string redirectUri = null;

            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    clientId = Constants.iOSClientId; //Constants is a class with the values stored in it
                    redirectUri = Constants.iOSRedirectUrl;
                    break;
    
                case Device.Android:
                    clientId = Constants.AndroidClientId;
                    redirectUri = Constants.AndroidRedirectUri;
                    break;
            }
            var authenticator = new OAuth2Authenticator(
                clientId,
                null,
                Constants.scopes,
                new Uri(Constants.AuthorizeUrl),
                new Uri(redirectUri),
                new Uri(Constants.AccessTokenUrl),
                null,
                true);
    
            authenticator.Completed += OnAuthCompleted;
            authenticator.Error += OnAuthError;
    
            AuthenticationState.Authenticator = authenticator;
            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
            presenter.Login(authenticator);
        }
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;
            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error -= OnAuthError;
            }
    
            User user = null;
            if (e.IsAuthenticated)
            {
                var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
                var response = await request.GetResponseAsync();
                if (response != null)
                {
                    string userJson = await response.GetResponseTextAsync();
    
                    user = JsonConvert.DeserializeObject<User>(userJson);
                }
    
                if (account != null)
                {
                    store.Delete(account, Constants.AppName);
                }
    
                await store.SaveAsync(account = e.Account, Constants.AppName);
    
            }
        }
    
        void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;
            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error -= OnAuthError;
            }
            Device.BeginInvokeOnMainThread(() =>
            {
                DisplayAlert("Error", "Error", "OK");
            });
            Debug.WriteLine("Authentication error: " + e.Message);
        }
    
  • Gandhi_123Gandhi_123 Member ✭✭

    Yes, I had done Google login with this code.
    Now I'm looking for google drive sync.

  • YahyaAlnaqeebYahyaAlnaqeeb Member ✭✭

    @Gandhi_123 said:
    Yes, I had done Google login with this code.
    Now I'm looking for google drive sync.

    Did you Achive that ??

  • Gandhi_123Gandhi_123 Member ✭✭

    @YahayaMboowa are you looking for drive sync?

  • YahyaAlnaqeebYahyaAlnaqeeb Member ✭✭

    @Gandhi_123 said:
    @YahayaMboowa are you looking for drive sync?

    yes i wana upload to google drive from Xamarin App

  • Gandhi_123Gandhi_123 Member ✭✭

    I have used web api in asp.net c#. with that i have sync with drive. @YahayaMboowa

Sign In or Register to comment.