我正试图在我正在开发的应用上实施Facebook登录。我按照Facebook开发人员指南进行操作!但是,只有在我的智能手机上安装了Facebook应用程序时,它才有效。如果我卸载它或者我尝试在没有安装Facebook App的智能手机上运行我的应用程序,它就会崩溃。
所以会发生什么,我点击登录按钮,它让我输入我的Facebook凭据。它登录但是当我尝试访问这样的配置文件时:
Profile.getCurrentProfile().getId()
它只给了我一个NullPointerException:
04-01 15:22:10.690 16758-16794/com.example.diogo.soulfiware E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at com.example.diogo.soulfiware.Fragments.FragmentSlideLogin$3$1.doInBackground(FragmentSlideLogin.java:173)
at com.example.diogo.soulfiware.Fragments.FragmentSlideLogin$3$1.doInBackground(FragmentSlideLogin.java:158)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
有趣的是,当它崩溃时,如果我第二次打开该应用程序,它会要求我注销为我之前插入的用户凭据,它会显示为"登录为:用户"并要求我退出!
我的问题是:我是否真的需要安装Facebook应用才能使登录工作?
答案 0 :(得分:0)
不一定需要Facebook应用,因为您还可以通过Web小部件登录进行操作。但是,当您是开发人员时,您需要在生成签名的apk时处理密钥哈希对。要保持两种方式(applogin和web widget登录),请使用此..
try {
//try to open facebook app if installed. Pass the username as u_name if required
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + u_name));
} catch (Exception e) {
//open the web login if app not installed. Pass the user id as u_id if required.
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + u_id));
}