#flutter #google-play-services #google-signin #http-status-code-403 #google-people-api
Вопрос:
Я использую Flutter и хотел бы узнать день рождения пользователя при входе в Google. Однако я могу получить только адрес электронной почты пользователя, отображаемое имя, но не дату рождения. Я попытался добавить область для получения дня рождения от API людей, но я получаю ошибку. Я могу успешно получить имя пользователя и адрес электронной почты, но я не могу получить день рождения. Пожалуйста, помогите..
Вот в чем ошибка.
W/.pumpit.pump_i(32752):Accessing hidden method Lsun/misc/Unsafe; >compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
I/flutter (32752): loading birthday
I/flutter (32752): loading completed
I/flutter (32752): api error
I/flutter (32752): {
I/flutter (32752): "error": {
I/flutter (32752): "code": 403,
I/flutter (32752): "message": "Request had insufficient authentication scopes.",
I/flutter (32752): "status": "PERMISSION_DENIED"
I/flutter (32752): }
I/flutter (32752): }
Вот мой код:
var googleIdToken;
FirebaseUser user;
Future<FirebaseUser> signInWithGoogle() async {
final GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: ['https://www.googleapis.com/auth/user.birthday.read']
);
final GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken);
googleIdToken = googleSignInAuthentication.idToken;
final AuthResult authResult = await _auth.signInWithCredential(credential);
user = authResult.user;
final host = "https://people.googleapis.com";
final endpoint= "/v1/people/me/connections?personFields=names,birthdays";
final header = await googleSignInAccount.authHeaders;
print('loading birthday');
final request = await http.get("$host$endpoint", headers: header);
print('loading completed');
if(request.statusCode == 200){
print('api working perfectly');
print(request.body);
} else {
print('api error');
print(request.body);
}
// connecting to mongo database
AuthService().googleLogin(googleIdToken).then((val) {
if (val.data['success']) {
var token2 = val.data['token'];
AuthService().getInfo(token2).then((val) async {
print('SUCCESS AUTHENTICATION');
var store = val.data['user'];
showDialog(context: context,
builder: (BuildContext context){
return _SuucessLogin();
});
EasyLoading.dismiss();
});
} else {
print('WRONG EMAIL/ PASS');
}
});
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await _auth.currentUser();
assert(currentUser.uid == user.uid);
return user;
}
Кто-нибудь может мне помочь? Заранее благодарю вас!
Комментарии:
1. Вы получили новый жетон после смены областей действия? @nit21
Ответ №1:
Вы должны использовать действие GetPerson для получения аутентифицированного пользователя, а не ListConnections, которое предназначено для получения контактов. См. документацию https://developers.google.com/people/v1/profiles#get_the_person_for_the_authenticated_user
Комментарии:
1. Я это проверю. Спасибо!