darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
193 stars 127 forks source link

At login The operation couldn’t be completed. (com.facebook.sdk.core error 8.) No more info. #325

Closed saulharov closed 1 year ago

saulharov commented 1 year ago

What version are you using?

flutter_facebook_auth: ^5.0.7

What OS and version are you using to local deploy your application?

Ventura 13.0.1

What platforms are you seeing the problem on?

IOS 16.1 iPhone 14 Pro (emulator) using

pubspec.yaml

name: myapp
description: My App
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
  sdk: '>=2.19.0 <3.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter
  video_player: ^2.4.7
  responsive_grid: ^2.1.0
  webview_flutter: ^4.0.2
  shared_preferences: ^2.0.15
  flutter_facebook_auth: ^5.0.7
  google_sign_in: ^5.4.2
  http: ^0.13.5
  custom_rating_bar: ^2.0.4
  permission_handler: ^10.2.0
  path_provider: ^2.0.11
  flutter_downloader: ^1.10.1+2
  jwt_decoder: ^2.0.1
  azure_ad_authentication: ^1.0.4

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/images/
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: Montserrat
      fonts:
        - asset: fonts/Montserrat-Regular.ttf
        - asset: fonts/Montserrat-Italic.ttf
          style: italic
        - asset: fonts/Montserrat-Bold.ttf
          weight: 700
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

Describe the Bug

The library and code WORKS without issues in Android emulator but, when I try to run in the iOS emulator it doesn't work. I press the button, sends me to Facebook, login and return me to the app but the error is displayed.

I tried to change LSApplicationQueriesSchemes using fbapi, fbauth2, fb-messenger-share-api and nothing.

I tried to change AppDelegate.swift according to this page https://developers.facebook.com/docs/ios/getting-started?locale=es_LA but i undo that because I didn't know what i was doing. And this too https://developers.facebook.com/docs/facebook-login/ios/

Tried tis https://facebook.meedu.app/docs/5.x.x/ios/ and, obviously, this https://github.com/darwin-morocho/flutter-facebook-auth/issues/261. This too https://www.reddit.com/r/iOSProgramming/comments/4vvaxa/the_operation_couldnt_be_completed/

I have no idea of swift, I'm just using dart.

I'm just tired to try so many things.

If you need more info don't hesitate to request it.

Expected Behavior

The user press the button, is sent to Facebook page for login, logins, the app receives the user info (email, name, id), and sends the user to another screen.

To Reproduce

The widget used inside screen:

Widget _facebookLoginButton(BuildContext context) {
    return TextButton(
      onPressed: () async {
        FacebookAuth.instance.login(
          permissions: ['public_profile', 'email']).then((value) {
            // Go to another screen
          }
        );
      },
      child: Text('login facebook'),
    );
  }

AppDelegate.swift Didn't change it but for reference

import UIKit
import Flutter
import flutter_downloader

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

private func registerPlugins(registry: FlutterPluginRegistry) {
    if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
       FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)
    }
}

Relevant log output

Launching lib/main.dart on iPhone 14 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           15.9s
Debug service listening on ws://127.0.0.1:59856/_Os5qS_TJIM=/ws
Syncing files to device iPhone 14 Pro Max...
[VERBOSE-2: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:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:315:18)
<asynchronous suspension>
#2      FacebookAuthPlatformImplementation.getUserData (package:flutter_facebook_auth_platform_interface/src/facebook_auth_implementation.dart:76:20)
<asynchronous suspension>

flutter doctor -v

[✓] Flutter (Channel stable, 3.7.0, on macOS 13.0.1 22A400 darwin-x64, locale
    es-419)
    • Flutter version 3.7.0 on channel stable at
      /Users/laclavees12345/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b06b8b2710 (9 days ago), 2023-01-23 16:55:55 -0800
    • Engine revision b24591ed32
    • Dart version 2.19.0
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/laclavees12345/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.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
      11.0.15+0-b2043.56-8887301)

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • AF689FEB-262D-4088-91F3-3D3E261BDB11 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Info.plist (iOS)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>My App</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>myapp</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb[FACEBOOK_ID]</string>
                <string>[GOOGLE_ID]</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>FacebookAppID</key>
    <string>[FACEBOOK_ID]</string>
    <key>FacebookClientToken</key>
    <string>[CLIENT_TOKEN]</string>
    <key>FacebookDisplayName</key>
    <string>[APP NAME]</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-share-api</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIApplicationSupportsIndirectInputEvents</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>remote-notification</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIStatusBarStyle</key>
    <string></string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
</dict>
</plist>

Podfile (iOS)

# Uncomment this line to define a global platform for your project
platform :ios, '16.1'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

AndroidManifest.xml

No response

MainActivity.java

No response

MainActivity.kt

No response

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 1 year ago

@saulharov according to your logs you are calling to getUserData. Please add the full dart code to check what is the problem

saulharov commented 1 year ago

@saulharov according to your logs you are calling to getUserData. Please add the full dart code to check what is the problem

@darwin-morocho

Note that this code works fine with Android, the problem is just in iOS.

Widget _facebookLoginButton(BuildContext context) {
    return TextButton(
      onPressed: () async {
        FacebookAuth.instance.login(
          permissions: ['public_profile', 'email']).then((value) {
            FacebookAuth.instance.getUserData().then((userData) async {
              Session.save(userData['name'], userData['email']);
              Navigator.pushNamedAndRemoveUntil(context, '/welcome', (Route<dynamic> route) => false);
            }
          }
        );
      },
      child: Text('login facebook'),
    );
  }
darwin-morocho commented 1 year ago

@saulharov before get the user data you must check if the login was successful

final result = await FacebookAuth.i.login();
if (result.status == LoginStatus.success) {
    final userData = await FacebookAuth.i.getUserData();
    Session.save(userData['name'], userData['email']);
    Navigator.pushNamedAndRemoveUntil(context, '/welcome', (Route<dynamic> route) => false);
} else {
    print(result.status);
    print(result.message);
}
saulharov commented 1 year ago

@saulharov before get the user data you must check if the login was successful

@darwin-morocho You are right, i changed the code and now I get:

flutter: LoginStatus.failed
flutter: The operation couldn’t be completed. (com.facebook.sdk.core error 309.)

I checked some answers, like https://github.com/facebook/facebook-ios-sdk/issues/1879, at it says that the clock/time was adjusted manually but I guarantee that I didn't change any clock in the system or emulator. It say that the problem might be with Facebook SDK 11 and later. What should I do about that?

saulharov commented 1 year ago

Its done. I don't know what happened or why it happened but I had to create a new project, add the library again, and it worked. I don't know how, I have no idea. Maybe some file that worked on and I edited trying to find an answer and I didn't remember... but whatever, it finally worked. I wish I could give a specific answer but I have none. Sorry. Thanks to @darwin-morocho the code correction.