flutter_twitter_login icon indicating copy to clipboard operation
flutter_twitter_login copied to clipboard

Example not working

Open kentcb opened this issue 6 years ago • 5 comments

Hi,

Thanks for writing this plugin.

I cloned the example and ran it on Android (Pixel) with the Twitter app installed. I get the same behavior I'm getting in my actual app:

  • the Twitter authorization view appears
  • I tap Connect
  • It says "Authenticating" then displays exactly the same Twitter authorization view
  • I tap Connect again, it says "Authenticating" again, then it takes me back to the app. However, the future returned by authorize never completes
  • If I tap Log in again, it errors with the below output in the debug console
Launching lib\main.dart on Pixel in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
D/NetworkSecurityConfig(17043): No Network Security Config specified, using platform default
W/ActivityThread(17043): handleWindowVisibility: no activity for token android.os.BinderProxy@d9a52dd
W/Twitter (17043): Authorize already in progress
W/Twitter (17043): Authorize already in progress
E/Twitter (17043): Authorization completed with an error
E/Twitter (17043): com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.
E/Twitter (17043): 	at com.twitter.sdk.android.core.identity.TwitterAuthClient.handleAuthorize(TwitterAuthClient.java:112)
E/Twitter (17043): 	at com.twitter.sdk.android.core.identity.TwitterAuthClient.authorize(TwitterAuthClient.java:103)
E/Twitter (17043): 	at com.roughike.fluttertwitterlogin.fluttertwitterlogin.TwitterLoginPlugin.authorize(TwitterLoginPlugin.java:88)
E/Twitter (17043): 	at com.roughike.fluttertwitterlogin.fluttertwitterlogin.TwitterLoginPlugin.onMethodCall(TwitterLoginPlugin.java:54)
E/Twitter (17043): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/Twitter (17043): 	at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/Twitter (17043): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/Twitter (17043): 	at android.os.MessageQueue.next(MessageQueue.java:326)
E/Twitter (17043): 	at android.os.Looper.loop(Looper.java:160)
E/Twitter (17043): 	at android.app.ActivityThread.main(ActivityThread.java:6669)
E/Twitter (17043): 	at java.lang.reflect.Method.invoke(Native Method)
E/Twitter (17043): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/Twitter (17043): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
W/terloginexampl(17043): Accessing hidden field Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe; (light greylist, reflection)
W/terloginexampl(17043): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
W/terloginexampl(17043): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection)

Output of flutter doctor -v:

[√] Flutter (Channel beta, v0.11.3, on Microsoft Windows [Version 10.0.17134.407], locale en-AU)
    • Flutter version 0.11.3 at C:\Users\Kent\Repository\flutter
    • Framework revision 72bf075e8d (8 days ago), 2018-11-09 20:36:17 -0800
    • Engine revision 5646e86a6f
    • Dart version 2.1.0 (build 2.1.0-dev.9.3 9c07fb64c4)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\Kent\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[√] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[!] VS Code (version 1.29.1)
    • VS Code at C:\Users\Kent\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
    • Pixel • FA6AF0303979 • android-arm64 • Android 9 (API 28)

! Doctor found issues in 1 category.

Debugging the Java side, I can see that the activity is being recreated, so when onActivityResult is called, authClientInstance is null and the result is never forwarded to it.

I tried changing initializeAuthClient to this:

private TwitterAuthClient initializeAuthClient(String consumerKey, String consumerSecret) {
    if (authClientInstance == null) {
        authClientInstance = configureClient(consumerKey, consumerSecret);
    }

    return authClientInstance;
}

I updated the call sites but also changed onActivityResult to call it with my hard-coded key and secret (didn't know how to get them otherwise). This behaved in exactly the same way except that there is no longer an "Authorize already in progress" error when I try the second time.

🤔 Any ideas?

kentcb avatar Nov 17 '18 23:11 kentcb

I get exactly the same behavior if I use the Flutter_Social_login by @YahiaAgwa here.

kentcb avatar Nov 18 '18 00:11 kentcb

Exactly same error here, the problem is in final TwitterLoginResult result = await twitterLogin.authorize();

Any help will be appreciated

pitazzo avatar Apr 16 '19 09:04 pitazzo

I got the same error of you @Pitazzo. When you try to print the message error shows "Failed to get request token" :/. Did you solve it?

biawar avatar Aug 22 '19 21:08 biawar

Hi,

I solved this by following below:

It is important to configure the callback URLs so that everything works correctly in your application.

You will have to use the following callback URLs:

Android - twittersdk://

iOS - twitterkit-CONSUMERKEY://

FOR MORE INFORMATION READ: https://developer.twitter.com/en/docs/basics/developer-portal/guides/callback-urls.html

x8Haider avatar Sep 14 '19 23:09 x8Haider

@x8Haider can you guide me exactly were to add "twittersdk://". I'm using firebase authentication with Twitter.

surveshoeb avatar Mar 03 '20 17:03 surveshoeb