我正在尝试将Facebook登录信息集成到我的应用中
我看了本教程:https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/
下载的Facebook SDK 3.5
一步一步-下载openssl,创建一个androIDkeystore,生成hashkey,在facebook开发控制台中创建一个应用程序,给它提供我的包名称,登录的活动以及在日志控制台中由设备打印给我的哈希码,如下所示:本教程建议我使用openssl生成的hashkey,将app_ID添加到字符串文件,并将所需的权限活动和元数据添加到androID清单文件
现在我打开该应用程序,然后单击“使用facebook登录”
它要求我允许访问用户个人资料,我单击确定
然后日志显示此异常:
10-16 19:51:20.718: W/Bundle(8444): Key com.facebook.platform.protocol.PROTOCol_VERSION expected String but value was a java.lang.Integer. The default value <null> was returned.10-16 19:51:20.718: W/Bundle(8444): Attempt to cast generated internal exception:10-16 19:51:20.718: W/Bundle(8444): java.lang.classCastException: java.lang.Integer10-16 19:51:20.718: W/Bundle(8444): at androID.os.Bundle.getString(Bundle.java:1040)10-16 19:51:20.718: W/Bundle(8444): at androID.content.Intent.getStringExtra(Intent.java:3412)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.AuthorizationClIEnt$KatanaLoginDialogAuthHandler.tryAuthorize(AuthorizationClIEnt.java:829)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.AuthorizationClIEnt.tryCurrentHandler(AuthorizationClIEnt.java:278)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.AuthorizationClIEnt.tryNextHandler(AuthorizationClIEnt.java:244)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.AuthorizationClIEnt$GetTokenAuthHandler.getTokenCompleted(AuthorizationClIEnt.java:778)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.AuthorizationClIEnt$GetTokenAuthHandler.completed(AuthorizationClIEnt.java:737)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.internal.PlatformServiceClIEnt.callback(PlatformServiceClIEnt.java:144)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.internal.PlatformServiceClIEnt.handleMessage(PlatformServiceClIEnt.java:128)10-16 19:51:20.718: W/Bundle(8444): at com.facebook.internal.PlatformServiceClIEnt.handleMessage(PlatformServiceClIEnt.java:54)10-16 19:51:20.718: W/Bundle(8444): at androID.os.Handler.dispatchMessage(Handler.java:99)10-16 19:51:20.718: W/Bundle(8444): at androID.os.Looper.loop(Looper.java:130)10-16 19:51:20.718: W/Bundle(8444): at androID.app.ActivityThread.main(ActivityThread.java:3906)10-16 19:51:20.718: W/Bundle(8444): at java.lang.reflect.Method.invokeNative(Native Method)10-16 19:51:20.718: W/Bundle(8444): at java.lang.reflect.Method.invoke(Method.java:507)10-16 19:51:20.718: W/Bundle(8444): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)10-16 19:51:20.718: W/Bundle(8444): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:598)10-16 19:51:20.718: W/Bundle(8444): at dalvik.system.NativeStart.main(Native Method)
这是一个警告,该应用并未因此而崩溃,但登录本身失败
这是我的登录流程代码:
import androID.content.Intent;import androID.os.Bundle;import androID.support.v4.app.Fragment;import androID.support.v4.app.FragmentActivity;import androID.support.v4.app.FragmentManager;import androID.support.v4.app.FragmentTransaction;import com.facebook.Session;import com.facebook.SessionState;import com.facebook.UilifecycleHelper;public class MainActivity extends FragmentActivity {private static final int SPLASH = 0;private static final int SELECTION = 1;private static final int FRAGMENT_COUNT = SELECTION + 1;private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];private boolean isResumed = false;private UilifecycleHelper uiHelper;private Session.StatusCallback callback = new Session.StatusCallback() { @OverrIDe public voID call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); }};/** * @param savedInstanceState */@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { // Todo auto-generated method stub super.onCreate(savedInstanceState); uiHelper = new UilifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); fragments[SPLASH] = fm.findFragmentByID(R.ID.splashFragment); fragments[SELECTION] = fm.findFragmentByID(R.ID.selectionFragment); FragmentTransaction transaction = fm.beginTransaction(); for (int i = 0; i < fragments.length; i++) { transaction.hIDe(fragments[i]); } transaction.commit();}private voID showFragment(int fragmentIndex, boolean addToBackStack) { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); for (int i = 0; i < fragments.length; i++) { if (i == fragmentIndex) { transaction.show(fragments[i]); } else { transaction.hIDe(fragments[i]); } } if (addToBackStack) { transaction.addToBackStack(null); } transaction.commit();}@OverrIDepublic voID onResume() { super.onResume(); uiHelper.onResume(); isResumed = true;}@OverrIDepublic voID onPause() { super.onPause(); uiHelper.onPause(); isResumed = false;}@OverrIDepublic voID onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data);}@OverrIDepublic voID onDestroy() { super.onDestroy(); uiHelper.onDestroy();}@OverrIDeprotected voID onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState);}private voID onSessionStateChange(Session session, SessionState state, Exception exception) { // Only make changes if the activity is visible if (isResumed) { FragmentManager manager = getSupportFragmentManager(); // Get the number of entrIEs in the back stack int backStackSize = manager.getBackStackEntryCount(); // Clear the back stack for (int i = 0; i < backStackSize; i++) { manager.popBackStack(); } if (state.isOpened()) { // If the session state is open: // Show the authenticated fragment showFragment(SELECTION, false); } else if (state.isClosed()) { // If the session state is closed: // Show the login fragment showFragment(SPLASH, false); } }}@OverrIDeprotected voID onResumeFragments() { super.onResumeFragments(); Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // if the session is already open, // try to show the selection fragment showFragment(SELECTION, false); } else { // otherwise present the splash screen // and ask the person to login. showFragment(SPLASH, false); }}
}
我究竟做错了什么?为什么不起作用?
解决方法:
问题是-
教程页面上的任何地方都没有说如果我尝试使用不是Facebook应用程序管理员或定义的假帐户之一的帐户登录,则必须退出沙盒模式
一旦我将应用程序置于实时模式,它就会起作用
总结以上是内存溢出为你收集整理的如何将Facebook登录集成到Android应用程序全部内容,希望文章能够帮你解决如何将Facebook登录集成到Android应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)