0maru / twitter_login

MIT License
54 stars 54 forks source link

TwitterLoginStatus always returns error #93

Closed Panagiss closed 2 years ago

Panagiss commented 2 years ago

While I have followed the guide step by step I cannot login on Firebase using Twitter. Here is my code:

Future signInWithTwitter() async {

    // Create a TwitterLogin instance
    final twitterLogin = TwitterLogin(
        apiKey: 'xxxxxxxxx',
        apiSecretKey: 'xxxxxxxxxxxxxxxxxxxx',
        redirectURI: 'my-app://');

    final authResult = await twitterLogin.login();

    switch (authResult.status) {

      case TwitterLoginStatus.loggedIn:
        // success
      print("succ");
        return await FirebaseAuth.instance.signInWithCredential(
          TwitterAuthProvider.credential(
            accessToken: authResult.authToken!,
            secret: authResult.authTokenSecret!,
          ),
        );

        break;

      case TwitterLoginStatus.cancelledByUser:
        // cancel
        print("cancel");
        break;

      case TwitterLoginStatus.error:
        // error
        print("error");
        break;

      default:
        print("def");
        break;
    }
  }

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" />
                <!-- Accepts URIs that begin with "example://gizmos” -->
                <!-- Registered Callback URLs in TwitterApp -->
                <data android:scheme="my-app" /> <!-- host is option -->
            </intent-filter>

And also I have included the updated callback in the Twitter Developer portal: image

Lastly I have set the API key and Secret in the Firebase console and of course I have enabled Twitter sign in.

Twitter_login: ^4.1.0 but I have also tried with 4.0.1

0maru commented 2 years ago

@Panagiss I think it works.

There are some things I would like you to go over.

  1. authtoken and authTokenSecret is not null or empty?
  2. If OAuth1.0a is available on Twitter Developer portal. Projects & Apps > your app > app > User authentication settings > Edit
Panagiss commented 2 years ago

Both authToken and authTokenSecret are NULL. image image

Also yes, I have enabled OAuth 1 image

shiv-walke commented 2 years ago

same error

katsuyax commented 2 years ago

I got the same error.

katsuyax commented 2 years ago

I made a PR because I fixed it. Can you see it?

0maru commented 2 years ago

@katsuyax @shivrajwalkeflutter @katsuyax 4.1.1 is now available. Could you please confirm the correction?

katsuyax commented 2 years ago

@0maru I confirmed that both API V1 and V2 can login and there is no problem with the status.

Panagiss commented 2 years ago

Still getting the same error. I have upgraded to 4.1.1 though. Any thoughts?

sandeepunify commented 2 years ago

I/flutter (11990): TwitterLoginStatus.error I/flutter (11990): null (authResult.authToken) I/flutter (11990): null (authResult.authTokenSecret) I/flutter (11990): HttpException: Failed Forbidden

Please solve this problem. i am getting every time this error.

sandeepunify commented 2 years ago

@0maru please update on this issue.

0maru commented 2 years ago

@Panagiss @sandeepunify Please add callback url of example:// to Twitter Developer. Then check if you can loggedIn with the twitter_login example project.

If the sample project works, please share your project with me via git or zip.

0maru commented 2 years ago

@sandeepunify Do not share the API KEY and API SECRET KEY. I recommend that you regenerate API KEY.

sandeepunify commented 2 years ago

@0maru 1 2

Login Code:

_loginWithTwitter() async { final twitterLogin = TwitterLogin( // Consumer API keys apiKey: 'api_key', // Consumer API Secret keys apiSecretKey: 'api_secret_key', // Registered Callback URLs in TwitterApp // Android is a deeplink // iOS is a URLScheme redirectURI: 'ujjain://', ); final authResult = await twitterLogin.login(); print(authResult.status); print(authResult.authToken); print(authResult.authTokenSecret); print(authResult.errorMessage);

// switch (authResult.status) {
//   case TwitterLoginStatus.loggedIn:
//     // success
//     break;
//   case TwitterLoginStatus.cancelledByUser:
//     // cancel
//     break;
//   case TwitterLoginStatus.error:
//     // error
//     break;
// }

}

twitter_login: 4.2.0 what should be use Type of App ? My app is hybrid Thanks

0maru commented 2 years ago

@katsuyax The code looks fine. Can we share a project at the minimum configuration that causes the error.

what should be use Type of App ?

Whichever you choose, it will work fine. Web App or Native App is recommended.

sandeepunify commented 2 years ago

@0maru https://github.com/sandeepunify/twitter_login please check and let me know what is the issue

katsuyax commented 2 years ago

@0maru I think the cause is different from other people.

I tried with a native app. The error I got was that the code returned a string with the ID expecting an int. This is due to the difference in JSON returned by Twitter between V1 and V2. So my fix fixed it.

0maru commented 2 years ago

@sandeepunify Thanks.

It worked fine.

If running on an emulator, regenerate the emulator. If you are using a terminal, reboot it.

sandeepunify commented 2 years ago

@0maru Thank for your reply At my side, I don't know why this is not working every time returning error. there can be problem of twitter app configuration settings?

sandeepunify commented 2 years ago

@0maru Problem has fixed now after searching your code on github I replaced final authResult = await twitterLogin.login() to final authResult = await twitterLogin.loginV2(); now working fine. Thanx for support

Panagiss commented 2 years ago

@0maru @katsuyax That was the problem for me also. When I used twitterLogin.loginV2() it returned success !! I got another error where it stated that I only have essential access and not elevated access, but that's another thing which is different.

So yeah the fix was to switch to V2 method!

Panagiss commented 2 years ago

Here is the full error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_auth/invalid-credential] The supplied auth credential is malformed or has expired. [ Failed to fetch resource from https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true, http status: 403, http response: {"errors":[{"message":"You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal.

I made the application for Elavated privileges, BUT my question why don't you use the V2 API and get rid of the need to applu for Elevated access? Am I missing something?

Thanks

0maru commented 2 years ago

@Panagiss Twitter API v1.1 is not available when creating a new application in twitter developer from November 15, 2021. You must apply to be able to use v1 if you need the user's email address. This is a problem because Twitter does not provide api v1 to all users. Also, api v2 does not provide a way to retrieve a user's email address.

And flutterfire_ui does not support loginV2. You must either make flutterfire_ui loginV2 compliant, use twitter_login, or enable api v1.