RuntimeException尝试使用其原生Android库对foursquare OAuth2进行身份验证进行身份验证

时间:2014-05-12 06:43:58

标签: android oauth foursquare

我有一个使用foursquare-android-oauth的应用程序,它在我测试的任何地方都运行正常,但我有一个报告崩溃的用户(Here is the crash report

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.foursquare.android.nativeoauth.TokenExchangeActivity$TokenExchangeTask)
       at android.os.Parcel.writeSerializable(Parcel.java:1259)
       at android.os.Parcel.writeValue(Parcel.java:1213)
       at android.os.Parcel.writeMapInternal(Parcel.java:571)
       at android.os.Bundle.writeToParcel(Bundle.java:1552)
       at android.os.Parcel.writeBundle(Parcel.java:585)
       at android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1615)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2316)
       at android.app.ActivityThread.access$1700(ActivityThread.java:117)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:130)
       at android.app.ActivityThread.main(ActivityThread.java:3701)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:507)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.io.NotSerializableException: com.foursquare.android.nativeoauth.TokenExchangeActivity
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1535)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
       at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
       at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
       at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
       at android.os.Parcel.writeSerializable(Parcel.java:1254)
       at android.os.Parcel.writeValue(Parcel.java:1213)
       at android.os.Parcel.writeMapInternal(Parcel.java:571)
       at android.os.Bundle.writeToParcel(Bundle.java:1552)
       at android.os.Parcel.writeBundle(Parcel.java:585)
       at android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1615)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2316)
       at android.app.ActivityThread.access$1700(ActivityThread.java:117)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:130)
       at android.app.ActivityThread.main(ActivityThread.java:3701)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:507)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
       at dalvik.system.NativeStart.main(NativeStart.java)

我不知道你需要什么细节,请评论,我会加上它!

我使用以下方式启动身份验证:

            private static final String CLIENT_ID                       = "MY CLIENT ID";
            final Intent intent = FoursquareOAuth.getConnectIntent(LoginActivity.this, CLIENT_ID);
                startActivityForResult(intent, REQUEST_CODE_FSQ_CONNECT);

然后用户被发送到4sq应用程序,我在这里再次拿起它:

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
        case REQUEST_CODE_FSQ_CONNECT:
            onCompleteConnect(resultCode, data);
            break;

        case REQUEST_CODE_FSQ_TOKEN_EXCHANGE:
            onCompleteTokenExchange(resultCode, data);
            break;

        default:
            super.onActivityResult(requestCode, resultCode, data);
    }
}



private void onCompleteConnect(final int resultCode, final Intent data) {
    final AuthCodeResponse codeResponse = FoursquareOAuth.getAuthCodeFromResult(resultCode, data);
    final Exception exception = codeResponse.getException();

    if (exception == null) {
        // Success.
        final String code = codeResponse.getCode();
        performTokenExchange(code);
    } else {
        if (exception instanceof FoursquareCancelException) {
            // Cancel.
            UiUtils.toastMessage(this, getString(R.string.login_cancelled));
        } else if (exception instanceof FoursquareDenyException) {
            // Deny.
            UiUtils.toastMessage(this, getString(R.string.login_denied));
        } else if (exception instanceof FoursquareOAuthException) {
            // OAuth error.
            UiUtils.toastMessage(this, getString(R.string.login_error));
        } else if (exception instanceof FoursquareUnsupportedVersionException) {
            UiUtils.toastMessage(this, getString(R.string.login_error));
        } else if (exception instanceof FoursquareInvalidRequestException) {
            UiUtils.toastMessage(this, getString(R.string.login_error));
        } else {
            UiUtils.toastMessage(this, getString(R.string.login_error));
        }
    }
}

private void onCompleteTokenExchange(final int resultCode, final Intent data) {
    final AccessTokenResponse tokenResponse = FoursquareOAuth.getTokenFromResult(resultCode, data);
    final Exception exception = tokenResponse.getException();

    if (exception == null) {
        final String accessToken = tokenResponse.getAccessToken();
        // Success.
        UiUtils.toastMessage(this, getString(R.string.connect_success));
        saveAccessToken(LoginActivity.this, accessToken);
        startActivity(new Intent(LoginActivity.this, MainFragmentActivity.class));
        finish();
    } else {
        if (exception instanceof FoursquareOAuthException) {
            // OAuth error.
            UiUtils.toastMessage(this, getString(R.string.login_error));
        } else {
            UiUtils.toastMessage(this, getString(R.string.login_error));
        }
    }
}

private void performTokenExchange(final String code) {
    final Intent intent = FoursquareOAuth.getTokenExchangeIntent(this, CLIENT_ID, CLIENT_SECRET, code);
    startActivityForResult(intent, REQUEST_CODE_FSQ_TOKEN_EXCHANGE);
}

public static boolean saveAccessToken(final Context context, final String accessToken) {
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    prefs.edit().putString(ACCESS_TOKEN_KEY, accessToken).commit();
    BackupUtils.requestBackup(context);
    return true;
}

它自身的例外没有意义:

`java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.foursquare.android.nativeoauth.okenExchangeActivity$TokenExchangeTask)`

我没有编辑TokenExchangeActivity $ TokenExchangeTask的原始代码,这段代码显然是可序列化的!

static class TokenExchangeTask extends AsyncTask<String, Void, AccessTokenResponse> implements Serializable

0 个答案:

没有答案