我正在进入Facebook。我需要获取用户电子邮件。 Facebook版本:
flutter_facebook_login:2.0.1。
我想使用:
print(profile [“ email”]);
但是我却没有。我想我需要连接某些东西或获得权限?
我的代码:
FacebookLogin fbLogin = FacebookLogin();
Future<void> signIn() async {
final FacebookLoginResult result =
await fbLogin.logInWithReadPermissions(['email', 'public_profile']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final token = result.accessToken.token;
final graphResponse = await http.get(
'https://graph.facebook.com/v2.12/me?fields=name,picture.width(800).height(800),first_name,last_name,email&access_token=${token}');
final profile = jsonDecode(graphResponse.body);
print(profile);
Navigator.push(
context, MaterialPageRoute(builder: (context) => RegisterForm()));
break;
case FacebookLoginStatus.cancelledByUser:
print(FacebookLoginStatus.cancelledByUser);
break;
case FacebookLoginStatus.error:
print(result.errorMessage);
break;
}}