darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
191 stars 124 forks source link

Unable to get Facebook user's email #360

Closed mycar98765 closed 5 months ago

mycar98765 commented 8 months ago

What version are you using?

6.0.1

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

macOS 13.5.1

What platforms are you seeing the problem on?

Android

pubspec.yaml

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

  cupertino_icons: 1.0.5
  …
  flutter_facebook_auth: 6.0.1
  …

Describe the Bug

I successfully logged into my Facebook account, but I can't seem to get their email.

Expected Behavior

I expected my Flutter app to create a Firebase Auth user using the Facebook user's email address.

To Reproduce

Here is some of my code:

onPressed: () async {
  final LoginResult result = await FacebookAuth.instance.login();
  if (result.status == LoginStatus.success) {
    final OAuthCredential credential = FacebookAuthProvider.credential(result.accessToken!.token);
    final UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(credential);

    print("Email: ${userCredential.user?.email}");
  }
},

Relevant log output

Email: null

flutter doctor -v

[✓] Flutter (Channel stable, 3.10.1, on macOS 13.5.1 22G90 darwin-x64, locale en-MY)
    • Flutter version 3.10.1 on channel stable at /Users/user/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3d8effc68 (4 months ago), 2023-05-16 17:59:05 -0700
    • Engine revision b4fb11214d
    • Dart version 3.0.1
    • DevTools version 2.23.1

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/user/Library/Android/sdk
    • Platform android-34, build-tools 33.0.2
    • 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)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

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

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

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] 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.81.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.70.0

[✓] Connected device (3 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • macOS (desktop)         • macos         • darwin-x64     • macOS 13.5.1 22G90 darwin-x64
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 116.0.5845.140

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

! Doctor found issues in 2 categories.

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.app">
    <!-- Required to fetch data from the internet. -->
    <uses-permission
        android:name="android.permission.INTERNET" />

    …

    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>

    …

    <application
        android:label="App" android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">

        <meta-data android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <meta-data android:name="com.facebook.sdk.ClientToken"
            android:value="@string/facebook_client_token" />

        …
    </application>
</manifest>

MainActivity.java

No response

MainActivity.kt

No response

index.html

No response

Info.plist (macOS)

No response

manav-kasare commented 8 months ago

Edit: I added the email permission in the Meta Developers console and it worked.

Same, did you find a solution?

darwin-morocho commented 8 months ago

@manav-kasare @mycar98765 keep in mind that this plugin only connect with the native facebook sdk so when you get the user profile data you only are making a http request to the graph API. You need to go to your facebook developers console and check that you have the right options enabled to be able to get the email user.

mycar98765 commented 7 months ago

@darwin-morocho @manav-kasare Sorry for the late reply. I checked and I selected the correct option. Here are the options I chose:

My chosen options
mycar98765 commented 7 months ago

@darwin-morocho Any updates?

hunter7149 commented 5 months ago

Any update? No solution found till now

darwin-morocho commented 5 months ago

Any update? No solution found till now

Sorry but this is not an issue of this plugin. You need to go to your Facebook developer console and check what options you need to enable to be able to get the user email.

Keep in mind of this plugin only makes a simple http request to the graph api to get the user profile data using the session access token.

nokia6290 commented 2 months ago

Add permissions parameter in the code

try {
  final LoginResult result = await FacebookAuth.instance.login(
    permissions: ['email', 'public_profile'],
  );