2

I am trying to use google drive API with flutter, testing on an android real device. I followed some youtube videos and medium blogs, i couldn't get it working.If there is any tutorial that you know, please post here.

I am currently using these packages googleapis: ^7.0.0, googleapis_auth: ^1.3.0.

I am stuck with an error that says about redirect_uri

enter image description here

This is a part of the code

import 'dart:io';

import 'package:google_drive_upload/helpers/constants.dart';
import 'package:googleapis/drive/v3.dart' as gdrive;
import 'package:googleapis_auth/auth_io.dart';
import 'package:url_launcher/url_launcher.dart';

class DriveService {
  List<String> _scopes = [gdrive.DriveApi.driveScope];

  getHttpClient() async {
    return await clientViaUserConsent(ClientId(clientId), _scopes, prompt);
  }

  prompt(String url) {
    launch(url);
  }

  upload(File file) async {
    var client = await getHttpClient();
    var drive = gdrive.DriveApi(client);
    var res = await drive.files.create(
      gdrive.File(),
      uploadMedia: gdrive.Media(file.openRead(), file.lengthSync()),
    );

    print('Response here ${res.toJson()}');
  }
}

I couldn't find redirect_uri in Oauth client in Oauth credentials for android (its available for web clients though).

Please help me to resolve this, been stuck here since 2 days :(

Edit 1 Tried with new fresh app with comoletely random appname so android domain won't clash, still same result.

3
  • 1
    looks like you are using code designed for a web app and not an android app. Either find the android code or create a web app credentials on google developer console. stackoverflow.com/q/65784077/1841839 Commented May 31, 2022 at 16:38
  • 1
    This may help: stackoverflow.com/a/70880091/6661043 Commented May 31, 2022 at 17:11
  • Hey i tried the steps given in that answer, i am getting same error with different port numbers. By the way my domain of android buid is com.example.google_drive_demo_app, does it has to do anything with it? because the youtube video i followed has his own domain Commented May 31, 2022 at 19:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.