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
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