0maru / twitter_login

MIT License
54 stars 54 forks source link

Auth redirect on Android failing #58

Closed stef0296 closed 3 years ago

stef0296 commented 3 years ago

I'm implementing this plugin in my app and it works perfectly for iOS. On Android however, it does not work for some reason. After successful login, I am stuck on the redirect screen and it does not return back to my app.

Screenshot: drive

Any idea on what's going wrong?

AndroidManifest.xml

<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="twittersdk"/>
</intent-filter>

Dart code

String consumerKey = '<--consumer key-->';
String consumerSecret = '<--consumer secret-->';
String redirectURI = 'twittersdk://';

final TwitterLogin twitterLogin = TwitterLogin(
  apiKey: consumerKey,
  apiSecretKey: consumerSecret,
  redirectURI: redirectURI,
);

final AuthResult authResult = await twitterLogin.login();
switch (authResult.status) {
  case TwitterLoginStatus.loggedIn:
    // success
    final AuthCredential credential = TwitterAuthProvider.credential(
     accessToken: authResult.authToken ?? '',
     secret: authResult.authTokenSecret ?? '',
    );
    firebaseUser = (await _auth.signInWithCredential(credential)).user;
    break;
  case TwitterLoginStatus.cancelledByUser:
  // cancel
  return null;
  case TwitterLoginStatus.error:
  // error
  return null;
  default:
  return null;
}
iamc1oud commented 3 years ago

Hi, I will share my snippets which I am using and works on android.

Try to change twittersdk with twitter

In android manifest file:

<!-- Twitter URI scheme -->
            <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="twitter"/> <!-- host is option -->
              </intent-filter>

The instance of TwitterLogin as:

 final twitterLogin = TwitterLogin(
        apiKey: AppConfig.twitterApiKey,
        apiSecretKey: AppConfig.twitterApiSecret,
        redirectURI: 'twitter://');

And in Twitter developer console using this as callback url twitter://

P.S. Also try to change app permission Read, Write, and Direct Message in Twitter dashboard.

100lvlmaster commented 3 years ago

Hi, I will share my snippets which I am using and works on android.

Try to change twittersdk with twitter

In android manifest file:

<!-- Twitter URI scheme -->
            <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="twitter"/> <!-- host is option -->
              </intent-filter>

The instance of TwitterLogin as:

 final twitterLogin = TwitterLogin(
        apiKey: AppConfig.twitterApiKey,
        apiSecretKey: AppConfig.twitterApiSecret,
        redirectURI: 'twitter://');

And in Twitter developer console using this as callback url twitter://

P.S. Also try to change app permission Read, Write, and Direct Message in Twitter dashboard.

This worked

iamc1oud commented 3 years ago

Good to hear that... šŸ‘šŸ˜‰