I am trying to gain access to gmail in my flutter app. However I cannot even go past the permission screen because of this invalid_client issue. I have already created the oauth 2.0 clientid in my Google Cloud and set the type to android. When I try to use the link I am given, I get this screen.
Error Screen
this is my code;
final clientId = ClientId('99899xxxxxxxx.apps.googleusercontent.com');
class GoogleService{
Future<void> authenticateAndFetchEmails() async {
final scopes = ['https://www.googleapis.com/auth/gmail.readonly'];
await clientViaUserConsent(clientId, scopes, (uri) {
// Open the URL in a web browser for user consent
print('Please visit the following URL and authorize the app: $uri');
}).then((AuthClient client) async {
final gmailApi = gmail.GmailApi(client);
final response = await gmailApi.users.messages.list('me');
final messages = response.messages ?? [];
for (var message in messages) {
final msg = await gmailApi.users.messages.get('me', message.id!);
final snippet = msg.snippet!;
if (snippet.contains('Debit') ||
snippet.contains('Account Name') ||
snippet.contains('Description')) {
print('Found email: ${msg.payload!.headers!.firstWhere((header) => header.name == 'Subject').value}');
}
}
}).catchError((e) {
print('Failed to authenticate or fetch emails: $e');
});
}
}
I have checked and crosschecked, my clientId is correct. what could be the issue
In the OAuth consent screen, I have added the relevant email as a part of the test users, I have used the client id given to me in the client_secret.json file as well as the clientId in the credential screen. Neither seem to work. I just created the clientId yesterday, so it cannot be invalid or expired. At this point, I need some help
Alexander Osuya Sty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.