darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
194 stars 129 forks source link

Error: init not called with valid version #265

Closed Milad-Akarie closed 1 year ago

Milad-Akarie commented 1 year ago

What version are you using?

4.4.0+1

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

macos

What platforms are you seeing the problem on?

web

pubspec.yaml

environment:
  sdk: ">=2.17.1 <3.0.0"

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

  google_sign_in: ^5.4.0
  flutter_facebook_auth: ^4.4.0+1

Describe the Bug

Facebook login shows error "Error: init not called with valid version" adding the following script AND calling FacebookAuth.i.webInitialize with same App Id makes login work

Expected Behavior

Show Facebook login dialog

To Reproduce

init the plugin await FacebookAuth.i.webInitialize( appId: "fb App id", cookie: true, xfbml: true, version: "v14.0", // tried v13.0 as well );

to main function then call FacebookAuth.instance.login()

Relevant log output

Error: init not called with valid version

flutter doctor -v

[✓] Flutter (Channel stable, 3.0.4, on macOS 12.4 21F79 darwin-arm, locale en-TR)
    • Flutter version 3.0.4 at /Users/milad/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 85684f9300 (13 days ago), 2022-06-30 13:22:47 -0700
    • Engine revision 6ba2af10bb
    • Dart version 2.17.5
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/milad/Library/Android/sdk
    • Platform android-32, build-tools 32.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2021.2)
    • 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.12+0-b1504.28-7817840)

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • HD1910 (mobile) • 74788f54 • android-arm64  • Android 11 (API 30)
    • macOS (desktop) • macos    • darwin-arm64   • macOS 12.4 21F79 darwin-arm
    • Chrome (web)    • chrome   • web-javascript • Google Chrome 103.0.5060.114

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

• No issues found!

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

No response

MainActivity.java

No response

MainActivity.kt

No response

index.html

<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
  <base href="$FLUTTER_BASE_HREF">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="qr_menu">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>Name</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    var serviceWorkerVersion = null;
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
// adding this script makes the error disapear
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId            : '<fb app id>',
      autoLogAppEvents : true,
      xfbml            : true,
      version          : 'v14.0'
    });
  };
</script>

<!-- Facebook JS CDN SDK -->

  <script>
    window.addEventListener('load', function(ev) {
      // Download main.dart.js
      _flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: serviceWorkerVersion,
        }
      }).then(function(engineInitializer) {
        return engineInitializer.initializeEngine();
      }).then(function(appRunner) {
        return appRunner.runApp();
      });
    });
  </script>
</body>
</html>

Info.plist (macOS)

No response

darwin-morocho commented 1 year ago

@Milad-Akarie I've tried to reproduce the issue without success.

Could you compare with this https://github.com/darwin-morocho/flutter-facebook-auth/tree/master/examples/with_provider example and replace the main.dartfile with your app id

eherbut commented 1 year ago

Have same issue on version 4.2.1