我正在研究parsefacebook用户。从它的文档中,我将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登录。上面的代码有什么问题?
谢谢!
最佳答案
您尚未在清单文件中包含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。