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

logInWithReadPermissions never ends #10

Closed
zigapk opened this issue Mar 19, 2018 · 11 comments
Closed

logInWithReadPermissions never ends #10

zigapk opened this issue Mar 19, 2018 · 11 comments

Comments

@zigapk
Copy link

zigapk commented Mar 19, 2018

Hi there!

I'm writing an app and am struggling to make facebook login work. I've followed all the instructions but logInWithReadPermissions method just doesn't seem to ever return (even if I log in or cancel the Facebook dialog).

My code:

FacebookLogin facebookLogin = new FacebookLogin();
  
  Future<String> loginWithFaceBook() async {
    return facebookLogin.logInWithReadPermissions(['email', 'public_profile'])
        .then((fbResult) {
      switch (fbResult.status) {
        case FacebookLoginStatus.loggedIn:
          return fbResult.accessToken.token;
        case FacebookLoginStatus.cancelledByUser:
          throw new StateError("Cancelled by user");
        case FacebookLoginStatus.error:
          throw new StateError(FacebookLoginStatus.error.toString());
      }
    });
  }

I know this is not an actual issue but I'd really appreciate some help.

Thank you in advance.

@roughike
Copy link
Owner

Hey!

A quick observation: you're using Futures, but without the async/await pattern. Instead, you're using then method to do something with the result. This won't work, simply because the then method is a callback.

Here's how you would refactor your code to get it return the token in a successful login case:

  Future<String> loginWithFaceBook() async {
   var result = await facebookLogin.logInWithReadPermissions(['email', 'public_profile'])

   switch (result.status) {
     case FacebookLoginStatus.loggedIn:
       return result.accessToken.token;
     case FacebookLoginStatus.cancelledByUser:
       throw new StateError("Cancelled by user");
     case FacebookLoginStatus.error:
       throw new StateError(result.error.toString());
   }

   return null;
  }

See if that helps! Personally, I would still do something like outlined here: https://github.com/roughike/flutter_facebook_login/blob/master/lib/flutter_facebook_login.dart#L16-L31

@zigapk
Copy link
Author

zigapk commented Mar 19, 2018

Thanks for your reply. I've just tried this and got the same result. My code as it is now:

FacebookLoginResult result =
              await
              facebookSignIn.logInWithReadPermissions(['email']);

              switch (result.status) {
                case FacebookLoginStatus.loggedIn:
                  print(result.accessToken.token);
                  break;
                case FacebookLoginStatus.cancelledByUser:
                  print('asdf');
                  break;
                case FacebookLoginStatus.error:
                  print('asdf');
                  break;
              }

I thought there might be a problem with me not registering native Facebook activity on the android side, but after double checking everything I just can't find the problem.

@roughike
Copy link
Owner

Is the problem apparent only with Android and not iOS? Also, could you post your pubspec dependencies here. I have a certain hunch about other plugins that may be intercepting things.

@zigapk
Copy link
Author

zigapk commented Mar 19, 2018

I've just tested it on iOS and it seems to work fine. And regarding the pubspec dependencies:

dependencies:
  flutter:
    sdk: flutter
  flutter_map: "^0.0.1"
  async_loader: "^0.1.1"
  location: "^1.1.7"
  url_launcher: "^2.0.2"
  flutter_facebook_login: "^1.0.2"
  flutter_localizations:
    sdk: flutter

I'll try to remove some plugins temporarily (starting with url_launcher) to check your whether any of them is intercepting facebook callback.

@zigapk
Copy link
Author

zigapk commented Mar 19, 2018

I've got my dependencies down to

dependencies:
  flutter:
    sdk: flutter
  flutter_facebook_login: "^1.0.3"

and the problem remains. I therefore assume that I've done something wrong while following the instructions for Android setup. However, I just can't seem to find the mistake.

My android manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.partyconapp.partycon">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- 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. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="partycon">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

        <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>
    </application>
</manifest>

@roughike
Copy link
Owner

Looking good so far. I'll assume your strings.xml is also fine?

Did you also stop and fully restart your app after you removed all the extra dependencies?

@zigapk
Copy link
Author

zigapk commented Mar 19, 2018

Yes strings.xml is fine and I did restart the app.

I've now successfully integrated this plugin into a blank flutter app so I'm considering this our internal issue. Thank you for all the support and sorry to bother you.

Have a good day!

@zigapk zigapk closed this as completed Mar 19, 2018
@roughike
Copy link
Owner

Please do comment once you find what was wrong, if possible! And if you can't figure out, I'm happy to help in private too.

Have a good one :)

@zigapk
Copy link
Author

zigapk commented Mar 20, 2018

I've found the issue. And it is so dumb I've surprised even myself. The whole story goes:

We have implemented native calls to launch and process Braintree payments via their drop-in UI. And to do that, we had to override onActivityResult method. There was an if (requestCode == BRAINTREE_REQUEST_CODE) to process Braintree results but super.onActivityResult() in the else part of this statement was somehow commented out for no good reason (and did not forward facebook results to the plugin).

So there it is, the obvious bug that made me check everything countless times and bang my head against the wall. But things like this happen.

Thank you for all the help and sorry to bother you.

@roughike
Copy link
Owner

That's not stupid at all!

I've actually banged my head into the wall numerous times because of the same reason. I was referring to this when I requested to see your pubspec file - I was going to check if you had any plugins that blocked this plugin from receiving results.

So this was really valuable, because now I can quicker identify the same problem if I or someone else comes across with it. Thanks for following up!

@scourgy
Copy link

scourgy commented Feb 13, 2020

@zigapk Can you share your Braintree code, please? I am having the same issue, but I am unable to resolve it. Difference is that I am not using any native code for the Braintree, entirely rely on the Braintree and Facebook plugins.

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

3 participants