2

「Parse」を使用してAndroidのFacebook統合用の簡単なプログラムを作成しましたが、次のコードを使用しましたが、私のコードとlogcatの例外を以下に示します:

main.java

パッケージcom.example.facbk;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook;
import com.parse.LogInCallback;
import com.parse.Parse;
import com.parse.ParseFacebookUtils;
import com.parse.ParseUser;
import android.net.ParseException;
import android.os.Bundle;
import android.provider.SyncStateContract.Constants;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    private static String APP_ID =" 454641867918042";
    private Facebook facebook;
    private AsyncFacebookRunner mAsyncRunner;
    String FILENAME = "AndroidSSO_data";
    Button login;
    private SharedPreferences mPrefs;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Parse.initialize(this, "454641867918042", "aWEd6rRA18hQJNVueCzeVUqqPkkDKAxp8moP3IP");// Try by Adding this method before ParseFacebookUtils.initialize()
        ParseFacebookUtils.initialize("454641867918042");
        setContentView(R.layout.activity_main);
        System.out.println("hello login");
        ParseFacebookUtils.logIn(this, new LogInCallback() {

            @Override
            public void done(ParseUser user, com.parse.ParseException arg1) {
                // TODO Auto-generated method stub
                 if (user == null) {
                      Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
                    } else if (user.isNew()) {
                      Log.d("MyApp", "User signed up and logged in through Facebook!");
                    } else {
                      Log.d("MyApp", "User logged in through Facebook!");
                    }
            }
            });

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
    }

}

ログキャット

07-11 11:04:34.751: I/dalvikvm(8972): threadid=3: reacting to signal 3
07-11 11:04:34.951: I/dalvikvm(8972): Wrote stack traces to '/data/anr/traces.txt'
07-11 11:04:35.190: I/dalvikvm(8972): threadid=3: reacting to signal 3
07-11 11:04:35.331: I/dalvikvm(8972): Wrote stack traces to '/data/anr/traces.txt'
07-11 11:04:35.631: I/System.out(8972): hello login
07-11 11:04:35.701: I/dalvikvm(8972): threadid=3: reacting to signal 3
07-11 11:04:35.801: D/AndroidRuntime(8972): Shutting down VM
07-11 11:04:35.801: I/dalvikvm(8972): Wrote stack traces to '/data/anr/traces.txt'
07-11 11:04:35.831: W/dalvikvm(8972): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
07-11 11:04:35.850: E/AndroidRuntime(8972): FATAL EXCEPTION: main
07-11 11:04:35.850: E/AndroidRuntime(8972): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.facbk/com.example.facbk.MainActivity}: com.facebook.FacebookException: Cannot use SessionLoginBehavior SSO_WITH_FALLBACK when com.facebook.LoginActivity is not declared as an activity in AndroidManifest.xml
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.os.Looper.loop(Looper.java:137)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.ActivityThread.main(ActivityThread.java:4424)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at java.lang.reflect.Method.invokeNative(Native Method)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at java.lang.reflect.Method.invoke(Method.java:511)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at dalvik.system.NativeStart.main(Native Method)
07-11 11:04:35.850: E/AndroidRuntime(8972): Caused by: com.facebook.FacebookException: Cannot use SessionLoginBehavior SSO_WITH_FALLBACK when com.facebook.LoginActivity is not declared as an activity in AndroidManifest.xml
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.facebook.Session.validateLoginBehavior(Session.java:992)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.facebook.Session.open(Session.java:915)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.facebook.Session.openForRead(Session.java:385)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.parse.auth.FacebookAuthenticationProvider.authenticate(FacebookAuthenticationProvider.java:156)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.parse.ParseUser.authenticateAsync(ParseUser.java:1091)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.parse.ParseUser.logInWithAsync(ParseUser.java:1108)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.parse.ParseUser.logInWithAsync(ParseUser.java:933)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.parse.ParseFacebookUtils.logIn(ParseFacebookUtils.java:338)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.parse.ParseFacebookUtils.logIn(ParseFacebookUtils.java:363)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at com.example.facbk.MainActivity.onCreate(MainActivity.java:35)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.Activity.performCreate(Activity.java:4465)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-11 11:04:35.850: E/AndroidRuntime(8972):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-11 11:04:35.850: E/AndroidRuntime(8972):     ... 11 more
07-11 11:04:36.190: I/dalvikvm(8972): threadid=3: reacting to signal 3
07-11 11:04:36.230: I/dalvikvm(8972): Wrote stack traces to '/data/anr/traces.txt'
07-11 11:04:36.421: I/dalvikvm(8972): threadid=3: reacting to signal 3
07-11 11:04:36.471: I/dalvikvm(8972): Wrote stack traces to '/data/anr/traces.txt'
4

2 に答える 2

1

私はそれがうまくいくかどうかわかりません:Parse.initialize()

onCreate のコードは

super.onCreate(savedInstanceState);
Parse.initialize(this, Constants.APPLICATION_ID, Constants.CLIENT_KEY);// Try by Adding this method before ParseFacebookUtils.initialize()
ParseFacebookUtils.initialize("454641867918042");
setContentView(R.layout.activity_main);

編集:

また、AndroidManifest.xml でインターネットのアクセス許可を確認してください。

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

編集:

以下をAndroidManifest.xmlに追加します

<activity
    android:name="com.facebook.LoginActivity"
     >
</activity>
于 2013-07-11T04:45:18.707 に答える
0

明らかに、非fb リクエストに対して ParseFacebookUtils.finishAuthentication() を呼び出しました。これを読んでください: https://www.parse.com/questions/nullpointerexceptions-from-the-facebook-authentication

別の理由として、この部分が変更された fb sdk 3.0.2 を使用していて、parse がその操作方法を認識していないことが考えられます。上のリンクにコメントしました。

これを使用してみてください:

/* This constant is private in new fb sdk 3.0.2, this is why we use it this way. */
private final static int DEFAULT_FACEBOOK_AUTH_ACTIVITY_CODE = 32665;

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == FB_HACK_CODE && data != null)
            ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
}
于 2013-08-15T11:52:13.960 に答える