darwin-morocho / flutter-facebook-auth

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

Email always return null after login #356

Closed MaximeDelhorme closed 9 months ago

MaximeDelhorme commented 9 months ago

What version are you using?

flutter_facebook_auth:5.0.11

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

macOS 12.5

What platforms are you seeing the problem on?

Android, iOS

pubspec.yaml

version: 1.1.0
publish_to: none

environment:
  sdk: ">=2.19.6 <3.0.0"

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

  app_tracking_transparency: ^2.0.2+4
  auto_size_text: ^3.0.0
  cached_network_image: ^3.2.3
  cloud_firestore: ^4.5.1
  connectivity_plus: ^3.0.6
  cupertino_icons: ^1.0.5
  date_format: ^2.0.5
  device_info_plus: ^8.0.0
  firebase_analytics: ^10.2.1
  firebase_auth: ^4.6.2
  firebase_core: ^2.10.0
  firebase_crashlytics: ^3.1.1
  firebase_messaging: ^14.4.1
  firebase_remote_config: ^4.0.1
  flutter_facebook_auth: ^5.0.11
  flutter_local_notifications: ^13.0.0
  flutter_native_timezone: ^2.0.0
  flutter_native_splash: ^2.1.0
  flutter_platform_widgets: ^3.3.2
  flutter_timezone: ^1.0.4
  flutter_riverpod: ^2.3.6
  fl_chart: ^0.50.1
  google_mobile_ads: ^2.4.0
  google_sign_in: ^5.4.0
  http: ^0.13.4
  in_app_update: ^4.0.1
  in_app_review: ^2.0.6
  internet_connection_checker: ^0.0.1+3
  intl: ^0.18.0
  jiffy: ^5.0.0
  lazy_load_indexed_stack: ^1.0.1
  mailto: ^2.0.0
  package_info_plus: ^3.0.2
  path_provider: ^2.0.11
  page_view_indicators: ^2.0.0
  platform: ^3.1.0
  riverpod_annotation: ^2.1.1
  share_plus: ^6.3.4
  shared_preferences: ^2.0.8
  the_apple_sign_in: ^1.1.1
  tutorial_coach_mark: ^1.2.4
  upgrader: ^5.0.0
  url_launcher: ^6.0.13
  uuid: ^3.0.5
  version: ^3.0.2
  webfeed_revised: ^0.7.2
  xml: ^6.1.0

Describe the Bug

I installed the library and manage to login on Android and iOS, but when I query the userdata, email always returns empty even though I have permission granted and advanced access turned on in the meta app page:

image

I am logging with an email linked to an admin role in the meta page. Here is a subset of the code I use:

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

    switch (result.status) {
      case LoginStatus.success:
        final AccessToken accessToken = result.accessToken!;
        credential = FacebookAuthProvider.credential(accessToken.token);

        var perm = await facebookSignIn.permissions;
        print(perm!.granted);
        print(facebookSignIn.getUserData());

Here are the output of print statements (replaced privte info by ): flutter: [email, public_profile, openid] flutter: Instance of 'Future<Map<String, dynamic>>' flutter: [User(displayName: email: null, isEmailVerified: false, isAnonymous: false, metadata: UserMetadata(creationTime: 2023-08-05 13:08:57.946Z, lastSignInTime: 2023-08-05 14:25:52.568Z), phoneNumber: null, photoURL: , providerData, [UserInfo(displayName: , email: null, phoneNumber: null, photoURL: null, providerId: facebook.com, uid: )], refreshToken:, tenantId: null, uid: ***), false]

I get this problem on both Android (simulator) and iOS (phone)

Expected Behavior

I expect to be able to retrieve the email address of the user. It used to work correctly, not sure what changed.

To Reproduce

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

    if (result.status == LoginStatus.success) {
      final AccessToken accessToken = result.accessToken!;
      credential = FacebookAuthProvider.credential(accessToken.token);
      var userData = await FacebookAuth.instance.getUserData();
      print(userData['email']);
    }

Relevant log output

No response

flutter doctor -v

[✓] Flutter (Channel stable, 3.10.2, on macOS 12.5 21G72 darwin-arm64, locale en-FR)
    • Flutter version 3.10.2 on channel stable at /Users/maxime/Documents/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9cd3d0d9ff (2 months ago), 2023-05-23 20:57:28 -0700
    • Engine revision 90fa3ae28f
    • Dart version 3.0.2
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/maxime/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/maxime/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b802.4-9586694)

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 12 (API 32) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 12.5 21G72 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 115.0.5790.170

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

• No issues found!

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="***">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
        <provider android:authorities="com.facebook.orca.provider.PlatformProvider" /> <!-- allows sharing to Messenger app -->
    </queries>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
    <application
        android:name="${applicationName}"
        android:label="***"
        android:usesCleartextTraffic="true"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:showWhenLocked="true"
            android:turnScreenOn="true">
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true"/>
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
                />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
            </intent-filter>
        </receiver>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

        <!-- Facebook Login configuration -->
        <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"/>

        <activity android:name="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />

        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <!-- Firebase Messaging configuration -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id"/>

        <!-- Sample AdMob App ID: ca-app-pub-6429424848874723~1890574352 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-6429424848874723~1890574352"/>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.com.shekarmudaliyar.social_share"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

    </application>
</manifest>

MainActivity.java

No response

MainActivity.kt

No response

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 9 months ago

This plugin only makes a request to the Facebook graph api when you are trying to get the user data. So this is not an issue of this plugin. Please go to the Facebook developers community to try to find a solution

MaximeDelhorme commented 9 months ago

Ok thanks for the comment