0

I'm trying to upload images to google photos or google drive I have followed the documentations and a lot of internet videos but it keeps send me the same error
my code is the same as this code literally but it doesn't work for me https://github.com/JideGuru/youtube_videos/tree/master/google_photos_upload/lib

the error that keeps showing I used oAuth 2 I think the problem is in it I entered the SHA1 and SHA256 correctly from my device and it didn't worked then I tried pushing my project first at firebase then modify it in google cloud but it keep showing the same error here is the code to upload,

import 'dart:convert';
import 'dart:io';


import 'package:googleapis_auth/auth_io.dart';
import 'package:url_launcher/url_launcher.dart';

import 'constants.dart';

class PhotosService {
  final List<String> _scopes = [
    'https://www.googleapis.com/auth/photoslibrary'
  ];

  Future<AuthClient> getHttpClient() async {
    AuthClient authClient =
    await clientViaUserConsent(ClientId(clientId), _scopes, _userPrompt).catchError((e) => print(e));
    return authClient;
  }

  upload(File file) async {
    AuthClient client = await getHttpClient();

    var tokenResult = await client.post(
      Uri.parse('https://photoslibrary.googleapis.com/v1/uploads'),
      headers: {
        'Content-type': 'application/octet-stream',
        'X-Goog-Upload-Content-Type': 'image/png',
        'X-Goog-Upload-Protocol': 'raw'
      },
      body: file.readAsBytesSync(),
    );
    print(tokenResult);
    var res = await client.post(
      Uri.parse(
          'https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate'),
      headers: {'Content-type':'application/json' },
      body: jsonEncode({
        "newMediaItems": [
          {
            "description": "item-description",
            "simpleMediaItem": {
              "fileName": "flutter-photos-upload",
              "uploadToken": tokenResult.body,
            }
          }
        ]
      }),
    );

    print(res.body);
  }

  _userPrompt(String url) {
    print(url);
    launch(url);

  }
}

maybe google added new restrictions for authentication so if anyone knows what should I do I would be thankful

  • Hi and welcome. Please be precise when descibring your issue and not only link to a github project and an error image. – jraufeisen Sep 08 '22 at 13:18
  • Thanks for the information I have done that and sorry for my poor explanation to the problem – ahmed wael Sep 08 '22 at 13:33
  • Take a look at this: https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch. – user18309290 Sep 08 '22 at 14:41
  • It's all for web application mine is an android application in the credentials page there's no URL to edit just the SHA-1 certificate fingerprint – ahmed wael Sep 08 '22 at 16:03

0 Answers0