Android twitter登录与面料集成,点击白屏然后关闭白屏

时间:2016-01-26 01:19:40

标签: java android api twitter twitter-fabric

我正在尝试使用fabric在android studio中设置twitter登录。一切都很好地构建,没有任何错误。

当我尝试在手机上运行应用程序并按下Twitter登录按钮时,它会进入白色屏幕并显示进度条,然后关闭并返回到带有twitter按钮的屏幕。它不会使应用程序崩溃,它只会给我一个错误。

我完全关注了twitters开发人员文档。 这是我得到的错误

01-25 16:58:59.359 32491-32491/com.myegotest.ego_17012016 E/Twitter: SSO auth activity not found
01-25 16:58:59.369 827-1358/? E/Parcel: Class not found when unmarshalling: com.twitter.sdk.android.core.TwitterAuthConfig
01-25 16:58:59.369 827-1358/? E/Parcel: java.lang.ClassNotFoundException: com.twitter.sdk.android.core.TwitterAuthConfig
01-25 16:58:59.369 827-1358/? E/Parcel:  Caused by: java.lang.NoClassDefFoundError: com/twitter/sdk/android/core/TwitterAuthConfig
01-25 16:58:59.369 827-1358/? E/Parcel:  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.twitter.sdk.android.core.TwitterAuthConfig" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: Invalid json: <?xml version="1.0" encoding="UTF-8"?>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: <hash>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter:   <error>Desktop applications only support the oauth_callback value 'oob'</error>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter:   <request>/oauth/request_token</request>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: </hash>
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: Failed to get request token
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: com.twitter.sdk.android.core.TwitterApiException: 401 Authorization Required
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at retrofit.Platform$Android$2$1.run(Platform.java:142)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at java.lang.Thread.run(Thread.java:841)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: Authorization completed with an error
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:215)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at android.os.Handler.handleCallback(Handler.java:733)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at android.os.Handler.dispatchMessage(Handler.java:95)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at android.os.Looper.loop(Looper.java:157)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at android.app.ActivityThread.main(ActivityThread.java:5293)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at java.lang.reflect.Method.invoke(Method.java:515)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter:     at dalvik.system.NativeStart.main(Native Method)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: Login with Twitter failure
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:215)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at android.os.Handler.handleCallback(Handler.java:733)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at android.os.Handler.dispatchMessage(Handler.java:95)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at android.os.Looper.loop(Looper.java:157)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at android.app.ActivityThread.main(ActivityThread.java:5293)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at java.lang.reflect.Method.invoke(Method.java:515)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit:     at dalvik.system.NativeStart.main(Native Method)

这是我的活动代码

package com.myegotest.ego_17012016;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterLoginButton;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
import io.fabric.sdk.android.Fabric;

public class SocialNetworkSelector_setupPage2 extends Activity {

    private static final String TWITTER_KEY = "key here";
    private static final String TWITTER_SECRET = "key here";
    private TwitterLoginButton twitterLoginButton;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new Twitter(authConfig));
        setContentView(R.layout.activity_social_network_selector_setup_page2);


        twitterLoginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);



        twitterLoginButton.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                // The TwitterSession is also available through:
                Twitter.getInstance().core.getSessionManager().getActiveSession();
                TwitterSession session = result.data;

                String msg = "@" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();

            }

            @Override
            public void failure(TwitterException exception) {
                Log.d("TwitterKit", "Login with Twitter failure", exception);
            }
        });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        twitterLoginButton.onActivityResult(requestCode, resultCode, data);
    }

}

这是我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.myegotest.ego_17012016">


    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-sdk tools:overrideLibrary="com.facebook"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name="android.support.multidex.MultiDexApplication">

        <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:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name" />

        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:theme="@style/AppTheme.NoActionBar" >

            <intent-filter android:autoVerify="true" >
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.myegotest.com" />
            </intent-filter>

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

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

        </activity>

        <activity
            android:name=".RegisterActivity"
            android:label="@string/title_activity_register"
            android:parentActivityName=".LoginActivity"
            android:theme="@style/AppTheme.NoActionBar" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".LoginActivity" />
        </activity>

        <activity android:name=".HomeActivity" >
        </activity>

        <activity
            android:name=".AccountConfirmationActivity"
            android:label="@string/title_activity_account_confirmation"
            android:parentActivityName=".LoginActivity"
            android:theme="@style/AppTheme" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".LoginActivity" />
        </activity>

        <activity android:name=".ForgotPassword" >
        </activity>

        <activity
            android:name=".ResetPassword"
            android:label="@string/title_activity_reset_password"
            android:theme="@style/AppTheme" >
        </activity>

        <activity
            android:name=".LetGetStarted_setupPage4"
            android:label="@string/title_activity_let_get_started"
            android:theme="@style/AppTheme" >
        </activity>

        <activity android:name=".UploadPhoto_setupPage3" >
    </activity>

        <activity android:name=".ImageListView" >
        </activity>

        <activity android:name=".ViewFullImage" >
        </activity>

        <activity android:name=".SocialNetworkSelector_setupPage2" >
        </activity>

        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="key here" />
    </application>

</manifest>

这是我的build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.myegotest.ego_17012016"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.facebook.android:facebook-android-sdk:4.9.0'
    compile('com.twitter.sdk.android:twitter:1.12.0@aar') {
        transitive = true;
    }
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'

}

1 个答案:

答案 0 :(得分:3)

您需要在the Twitter App Settings中设置回调网址。它实际上与您设置的内容无关,它将自动替换。