Open DavidHajum opened 1 month ago
@darwin-morocho A same issue facing.
Error
flutter: AccessTokenType.limited [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(FAILED, The operation couldn’t be completed. (com.facebook.sdk.core error 8.), null, null)
@DavidHajum try this version 6.0.0 for temporary solution. working for me.
The solution of @furkan-wve seems to work for now, thanks :)
I'm experiencing a similar issue.
Seems that the sign in options are what fails, ex. signInWithCredential
Same problem still continue.There is no issue in version 6.2.0, but there is an issue in version 7.0.2. It happens when trying to log in with the limited.facebook.com domain.
Dart Code:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final _auth = FacebookAuth.instance;
late LoginPageState _state;
@override
void initState() {
super.initState();
_init();
}
Future<void> _init() async {
setState(() {
_state = LoginLoading();
});
final accessToken = await _auth.accessToken;
if (accessToken != null) {
await _getUserProfile(accessToken.tokenString);
} else {
setState(() {
_state = LoginNotAuthenticated();
});
}
}
Future<void> _getUserProfile(String accessToken) async {
final data = await _auth.getUserData();
if (data.isEmpty) {
await _logout();
return;
}
setState(() {
_state = LoginSuccessful(
User(
userId: data['id'] as String,
accessToken: accessToken,
name: data['name'] as String,
pictureProfile: data['picture']?['data']?['url'] as String,
email: data['email'] as String,
),
);
});
}
Future<void> _logout() async {
await _auth.logOut();
setState(() {
_state = LoginNotAuthenticated();
});
}
Future<void> _login() async {
setState(() {
_state = LoginLoading();
});
final result = await _auth.login(
loginTracking: LoginTracking.limited,
);
switch (result.status) {
case LoginStatus.success:
await _getUserProfile(result.accessToken!.tokenString);
case LoginStatus.cancelled:
case _:
setState(() {
_state = LoginNotAuthenticated();
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
width: double.infinity,
height: double.infinity,
child: Column(
children: [
ElevatedButton(
onPressed: () {
_logout();
},
child: Text("logout")),
Center(
child: switch (_state) {
LoginLoading() => const CircularProgressIndicator(),
LoginNotAuthenticated() => ElevatedButton(
onPressed: _login,
child: const Text('Login'),
),
LoginSuccessful(user: final User user) => Text(
prettyPrint(
user.toJson(),
),
),
},
),
],
),
),
);
}
}
// Abstract base class representing login page states
sealed class LoginPageState {}
// State representing the login page is loading
class LoginLoading extends LoginPageState {}
// State representing the user is not logged in
class LoginNotAuthenticated extends LoginPageState {}
// State representing the user is successfully logged in
class LoginSuccessful extends LoginPageState {
final User user;
LoginSuccessful(this.user);
}
class User {
final String userId;
final String accessToken;
final String name;
final String? pictureProfile;
final String? email;
User({
required this.userId,
required this.accessToken,
required this.name,
required this.pictureProfile,
required this.email,
});
Map<String, dynamic> toJson() => {
'userId': userId,
'name': name,
'accessToken': accessToken,
'pictureProfile': pictureProfile,
'email': email,
};
}
String prettyPrint(Map json) {
JsonEncoder encoder = new JsonEncoder.withIndent(' ');
String pretty = encoder.convert(json);
return pretty;
}
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(FAILED, The operation couldn’t be completed. (com.facebook.sdk.core error 8.), null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
message_codecs.dart:648
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
platform_channel.dart:334
<asynchronous suspension>
#2 FacebookAuthPlatformImplementation.getUserData (package:flutter_facebook_auth_platform_interface/src/facebook_auth_implementation.dart:84:20)
facebook_auth_implementation.dart:84
<asynchronous suspension>
#3 FacebookAuth.getUserData (package:flutter_facebook_auth/flutter_facebook_auth.dart:70:20)
flutter_facebook_auth.dart:70
<asynchronous suspension>
#4 _LoginPageState._getUserProfile (package:flutter_riverpod_template/new_page.dart:41:18)
new_page.dart:41
<asynchronous suspension>
#5 _LoginPageState._login (package:flutter_riverpod_template/new_page.dart:78:9)
new_page.dart:78
<asynchronous suspension>
I had the same problem. I solved it using the following code.
TrackingStatus? status;
if (Platform.isIOS) {
status = await AppTrackingTransparency.trackingAuthorizationStatus;
}
final LoginResult result = await FacebookAuth.instance.login(
permissions: ['email', if (Platform.isAndroid || status == TrackingStatus.authorized) 'public_profile'],
loginBehavior: LoginBehavior.nativeWithFallback,
loginTracking: status == TrackingStatus.authorized ? LoginTracking.enabled : LoginTracking.limited,
);
What version are you using?
7.0.1
What OS and version are you using to local deploy your application?
macOS 14.5
What platforms are you seeing the problem on?
iOS
pubspec.yaml
Describe the Bug
I get this error, when I try to log in on iOS:
PlatformException(FAILED, The operation couldn’t be completed. (com.facebook.sdk.core error 8.), null, null)
I followed this instruction for the setup and tried this suggestion on StackOverflow, but no luck so far.
My code currently looks like this:
The login functionality works without problems on Android.
I'm using a test account to log in.
Expected Behavior
The login function returns normally
To Reproduce
Make a login call
Relevant log output
No response
flutter doctor -v
Info.plist (iOS)
No response
Podfile (iOS)
No response
AndroidManifest.xml
No response
MainActivity.java
No response
MainActivity.kt
No response
index.html
No response
Info.plist (macOS)
No response