使用flutter_facebook_login pacakage和https://medium.com/flutter-community/flutter-facebook-login-77fcd187242链接,出现Facebook登录窗口,但立即关闭。 当我使用其他facebook帐户尝试我的应用程序时,会出现此问题,但它适用于我自己的facebook id。
问题很可能与用户访问令牌有关,使用该应用程序时如何允许多个用户访问登录功能?
显示的错误是:
W/ActivityThread(30135): handleWindowVisibility: no activity for token android.os.BinderProxy@6ccdd3
I/Timeline(30135): Timeline: Activity_launch_request time:15389566 intent:Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) }
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_facebook_login/flutter_facebook_login.dart';
import 'package:flutter_signin_button/flutter_signin_button.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(FacebookLoginPage());
}
class FacebookLoginPage extends StatefulWidget {
@override
_FacebookLoginPageState createState() => _FacebookLoginPageState();
}
class _FacebookLoginPageState extends State<FacebookLoginPage> {
bool isLoggedIn = false;
var profileData;
var facebookLogin = FacebookLogin();
void onLoginStatusChanged(bool isLoggedIn, {profileData}) {
setState(() {
this.isLoggedIn = isLoggedIn;
this.profileData = profileData;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Facebook Login"),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.exit_to_app,
color: Colors.white,
),
onPressed: () => facebookLogin.isLoggedIn
.then((isLoggedIn) => isLoggedIn ? _logout() : {}),
),
],
),
body: Container(
child: Center(
child: isLoggedIn
? _displayUserData(profileData)
: _displayLoginButton(),
),
),
),
);
}
void initiateFacebookLogin() async {
var facebookLoginResult =
await facebookLogin.logInWithReadPermissions(['email']);
switch (facebookLoginResult.status) {
case FacebookLoginStatus.error:
onLoginStatusChanged(false);
break;
case FacebookLoginStatus.cancelledByUser:
onLoginStatusChanged(false);
break;
case FacebookLoginStatus.loggedIn:
var graphResponse = await http.get(
'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email,picture.height(200)&access_token=${facebookLoginResult.accessToken.token}');
var profile = json.decode(graphResponse.body);
print(profile.toString());
onLoginStatusChanged(true, profileData: profile);
break;
}
}
_displayUserData(profileData) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 200.0,
width: 200.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
profileData['picture']['data']['url'],
),
),
),
),
SizedBox(height: 28.0),
Text(
"Logged in as: ${profileData['name']}",
style: TextStyle(
fontSize: 20.0,
),
),
],
);
}
_displayLoginButton() {
return Container(
height: 50,
child: SignInButton(
Buttons.Facebook,
// mini: true,
// width: 200.0,
text: "Sign in with Facebook",
onPressed: () {
initiateFacebookLogin();
},
),
);
// return RaisedButton(
// child: Text("Login with Facebook"),
// onPressed: () => initiateFacebookLogin(),
// );
}
_logout() async {
await facebookLogin.logOut();
onLoginStatusChanged(false);
print("Logged out");
}
}
答案 0 :(得分:0)
我找到了解决方案。 它在Facebook开发人员控制台中处于应用程序的开发状态。 您必须将应用公开,以便其他用户登录。