Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login fails on iOS PlatformException(FAILED, The operation couldn’t be completed. (com.facebook.sdk.core error 8.), null, null) #417

Open
davidsturm96 opened this issue Jul 22, 2024 · 9 comments

Comments

@davidsturm96
Copy link

davidsturm96 commented Jul 22, 2024

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

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # Getx
  get: ^4.6.6
  get_storage: ^2.1.1

  # Firebase
  firebase_core: ^2.27.2
  firebase_messaging: ^14.9.4
  firebase_analytics: ^10.9.0
  firebase_remote_config: ^4.3.19

  # Socials
  google_sign_in: ^6.2.1
  flutter_facebook_auth: ^7.0.1
  sign_in_with_apple: ^6.1.1

  # Modals and popups
  modal_bottom_sheet: ^3.0.0-pre
  adaptive_dialog: ^2.1.0
  flutter_platform_alert: ^0.5.1
  toastification: ^1.2.1

  http: ^1.2.1
  flutter_native_splash: ^2.4.0
  intl: ^0.19.0
  custom_check_box: ^0.0.4
  share_plus: ^7.2.2
  url_launcher: ^6.2.5
  font_awesome_flutter:
  flutter_html: ^3.0.0-beta.2
  jovial_svg: ^1.1.20
  flutter_spinkit: ^5.2.0
  flutter_form_builder: ^9.2.1
  form_builder_validators: ^11.0.0
  shimmer: ^3.0.0
  fancy_shimmer_image: ^2.0.3
  infinite_scroll_pagination: ^4.0.0
  app_tracking_transparency: ^2.0.4
  package_info_plus: ^4.0.2
  version: ^3.0.2
  store_redirect: ^2.0.2
  cached_network_image: ^3.3.1
  easy_localization: ^3.0.5
  image_picker: ^1.1.0
  file_picker: ^8.0.1
  flutter_avif: ^2.3.0
  flutter_keyboard_visibility: ^6.0.0
  timezone: ^0.9.2
  expand_tap_area: ^1.1.1
  scroll_to_index: ^3.0.1
  rive: ^0.13.7
  app_settings: ^5.1.1
  permission_handler: ^11.3.0
  flutter_quill: ^9.4.6
  flutter_quill_extensions: ^9.4.6
  vsc_quill_delta_to_html: ^1.0.3
  animated_page_transition:
    git: https://github.com/DavidHajum/animated_page_transition.git
  dots_indicator: ^3.0.0
  auto_size_text: ^3.0.0
  flutter_phoenix: ^1.1.1
  feather_icons_svg:
    git:
      url: "https://github.com/FrazeColder/feather_icons_svg"
  dotted_border: ^2.1.0
  flutter_countdown_timer: ^4.1.0
  flutter_verification_code: ^1.1.7
  app_links: ^5.0.0
  app_badge_plus: ^1.0.0
  flutter_widget_from_html: ^0.15.1
  html: ^0.15.4
  flutter_lightbox: ^0.1.3
  flutter_slidable: ^3.1.1

  cupertino_icons: ^1.0.6

dependency_overrides:
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

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:

final LoginResult result = await FacebookAuth.instance.login();
final userData = await FacebookAuth.instance.getUserData();

if (result.accessToken != null) {
  do more stuff ...

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

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale en-DE)
    • Flutter version 3.22.2 on channel stable at /Users/david/Desktop/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (7 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/david/Library/Android/sdk
    • Platform android-34, build-tools 33.0.2
    • ANDROID_HOME = /Users/david/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google
    Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.91.1)
    • VS Code at /Users/david/Desktop/setups/Visual Studio Code.app/Contents
    • Flutter extension version 3.92.0

[✓] Connected device (3 available)
    • iPhone 15 (mobile)              • 39C4731E-F868-4097-BFC0-3A0BA258AA72 • ios          •
      com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64 • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin       • macOS 14.5 23F79 darwin-arm64

[✓] Network resources
    • All expected network resources are available.

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

@furkan-wve
Copy link

furkan-wve commented Jul 23, 2024

@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)

@furkan-wve
Copy link

@DavidHajum try this version 6.0.0 for temporary solution. working for me.

@davidsturm96
Copy link
Author

The solution of @furkan-wve seems to work for now, thanks :)

@lukeirvin
Copy link

I'm experiencing a similar issue.

Seems that the sign in options are what fails, ex. signInWithCredential

@malikdoksoz
Copy link

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>

@nikiforosper
Copy link

nikiforosper commented Aug 19, 2024

I had the same problem. I solved it using the following code.

  1. Check AppTrackingTraspareny status (app_tracking_transparency package)
  2. Handle facebook login permission & loginTracking
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,
);

@tannker
Copy link

tannker commented Sep 10, 2024

I stumbled on this issue today as well as a result of upgrading the package.

As far as I understand, getUserData cannot be used with Limited login as it goes over Graph API and the token received from Limited Login just does not work with Graph API.

Tracking status can be indeed used to toggle between Limited and normal login, however that is not acceptable solution as in case Limited Login various profile information seems to be missing (name, email, profile picture, etc). Or at least I do not find currently any place to where it is populated.

As per Facebook documentation (https://developers.facebook.com/docs/facebook-login/limited-login/ios/) in case of Limited Login it is possible specify permissions and as a result some profile information is populated for a successful login (https://developers.facebook.com/docs/facebook-login/limited-login/ios/#implement-limited-login).

Currently I do not understand where in flutter_facebook_auth this populated profile information is available. Is it populated at all @darwin-morocho ?

@AadarshaSadan
Copy link

the solution of @furkan-wve works me too

@WingCH
Copy link

WingCH commented Nov 18, 2024

version: 7.1.1
i can reproduce in ios real device (simulator is fine)
workaround: only get [email] instead of ['email', 'public_profile']

    final result = await _auth.login(
      permissions: ['email'],
      loginTracking: LoginTracking.limited,
      nonce: _nonce,
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants