Android:如何将parse.com链接到Facebook

时间:2015-07-11 17:25:53

标签: android facebook parse-platform

我正在研究ParseFacebookUser。从其文档中,我将facebook登录模块编码如下:

代码:

@Override  
    protected void onResume() 
    {  
        super.onResume();  
        ....

        Parse.initialize(this, "XXX", "XXX"); 
        ParseFacebookUtils.initialize(this);

        // FB: Logs 'install' and 'app activate' App Events.
        AppEventsLogger.activateApp(this);

        List<String> permissions = Arrays.asList("user_birthday", "user_location", "user_friends", "email", "public_profile");
        ParseFacebookUtils.logInWithReadPermissionsInBackground(this, permissions, new LogInCallback() 
        {
              @Override
              public void done(ParseUser user, ParseException err) 
              {
                    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!");
                    }
              }
        });


    }

清单:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/MyTheme" >
        <activity
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity android:name="com.abc.user.LoginActivity"             android:screenOrientation="portrait"/>
        <activity android:name="com.abc.user.RegisterActivity"              android:screenOrientation="portrait"/>
        <activity android:name="com.abc.user.User_leaderboard"              android:screenOrientation="portrait"/>   
        <activity android:name="com.facebook.LoginActivity" 
                        android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name" /> />

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>   

    </application>

logcat的:

07-12 01:13:57.488: E/AndroidRuntime(23542): Caused by: Log in attempt failed: FacebookActivity could not be started. Please make sure you added FacebookActivity to the AndroidManifest.
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.facebook.login.LoginManager.startLogin(LoginManager.java:381)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:261)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.parse.FacebookAuthenticationProvider.authenticateAsync(FacebookAuthenticationProvider.java:155)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.parse.ParseAuthenticationProvider.logInAsync(ParseAuthenticationProvider.java:50)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.parse.ParseFacebookUtils.logInAsync(ParseFacebookUtils.java:265)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:161)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:173)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at com.abc.abc.First.onResume(First.java:144)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1210)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at android.app.Activity.performResume(Activity.java:5512)
07-12 01:13:57.488: E/AndroidRuntime(23542):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2948)
07-12 01:13:57.488: E/AndroidRuntime(23542):    ... 12 more

问题:

引起:登录尝试失败:无法启动FacebookActivity。请确保您已将FacebookActivity添加到AndroidManifest。没有页面重定向登录facebook。上面的代码有什么问题?

谢谢!

1 个答案:

答案 0 :(得分:23)

您尚未在Manifest文件中包含Facebook登录活动。加上这个。

<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" />

有关详细信息,请参阅Facebook Android SDK