Search code examples
androidtwitter

Twitter Login failed on only latest Twitter app in my android app


My App is released on PlayStore, and Twitter Login has been working fine.

But today, I found the Twitter login doesn't work!

My app uses Twitter SDK, not Firebase Auth.

implementation "com.twitter.sdk.android:twitter-core:3.3.0"

The login code is:

TwitterAuthClient.authorize(activity, object : Callback<TwitterSession>() {
    override fun success(result: Result<TwitterSession?>) {

        // 'authorize' success and `result.data?.authToken` is not null but 
        // `result.data?.authToken?.token` and `result.data?.authToken?.secret` are null

        TwitterCore.getInstance().apiClient.accountService.verifyCredentials(false, false, true).enqueue(object : Callback<User>() {
            override fun success(result: Result<User?>) {

            }
        
            override fun failure(exception: TwitterException) {
                // 403 Error! - com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403
            }
        })
    }

    override fun failure(e: TwitterException) {
        
    }
})
  1. If the Twitter App is not installed on the device, the twitter login is processed on Web Browser and there is no problem. (Login Success)
  2. If the old Twitter App is installed on the device, the twitter login is processed on the Twitter app and there is no problem. (Login Success)
  3. If the latest Twitter App is installed on the device(9.54.0-release.0) the twitter login is processed on the Twitter app and the problem occurs (Login Fail)

My app doesn't change anything. I think the latest Twitter app has some problem. But I don't know how handle this.

My co-worker checked this issue too. He had an older version of Twitter app 9.32.0-release.0 on his device. At that time the Twitter login works fine. After he updated the Twitter app to 9.54.0-release.0, the Twitter login doesn't work.


[update]

I created a new sample app and am doing a test. But my new sample app works fine (twitter login works fine!). My released app still doesn't work! (cannot login using twitter).

The official Twitter App(9.54.0-release.0) doesn’t return token information to my released app. But it returns token information to my new sample app. I’m confused.

The two apps are using the same SDK. (implementation com.twitter.sdk.android:twitter-core:3.3.0) And the kotlin codes are identical. And they are using the same customer key and customer secret.

I found that something weird.

The new sample app’s twitter login UI is: enter image description here

But my released app’s twitter login UI is: enter image description here

It doesn’t look the same! Why are they different?

Same SDK, same code, same consumer key/secret!

Could you give me some hints, please? When the second screenshot occurs? What condition? Can I know, please?


Solution

  • I checked the twitter-kit-android(Android Twitter SDK).

    The first screenshot is shown when my app can search the com.twitter.android on the device. The second screenshot is shown when my app cannot search the com.twitter.android on the device.

    My released app has the queries tag:

    <queries>
        <package android:name="com.twitter.android" />
    </queries>
    

    Because of this, my app can search the twitter app.

    The twitter sdk checks that if the app can search com.twitter.android then start SingleSignOnActivity, and it doesn't return token information. But if the app cannot search com.twitter.android then start OAuthActivity, and it returns token information.


    [update]

    Actually, when I remove the queries tag, my app still can search com.twitter.android.

    In this case, I checked the Merged Manifest. Even though I don't use the queries tag, other libraries may use the queries tag.

    I checked the Merged Manifest, I can found that one library use below queries:

    <queries>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </queries>
    

    After I remove the library dependency, my app cannot search the com.twitter.android and login works fine