[英]Facebook login doesn't work if app is not installed
I'm trying to implement the Facebook Login on an app that i'm developing. 我正在尝试在我正在开发的应用程序上实现Facebook登录。 I followed the Facebook Developer guide and it's working!
我遵循了Facebook开发人员指南,并且可以正常工作! BUT, it only works if the Facebook App is installed on my smartphone.
但是,仅当我的智能手机上安装了Facebook App时,它才有效。 If i unninstall it or i try to run my app on a smartphone that does not have the Facebook App installed, it just crashes.
如果我卸载它或尝试在未安装Facebook应用程序的智能手机上运行我的应用程序,它将崩溃。
So what happens is that i tap the login button and it askes me to put in my Facebook credentials. 因此,发生的事情是我点击登录按钮,并要求我输入我的Facebook凭据。 It logs in but when i try to access the Profile like this:
它登录,但是当我尝试像这样访问配置文件时:
Profile.getCurrentProfile().getId()
It just gives me a NullPointerException: 它只是给我一个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)
Funny thing is that when it crashes, if I open the app a second time, it asks me to logout as the user credentials I previously inserted and it says "Logged in as: User" and asks me to logout! 有趣的是,当它崩溃时,如果我第二次打开该应用程序,它会要求我以先前插入的用户凭据注销,并显示“以用户身份登录:”并要求我注销!
My question is: Do i really need the Facebook app to be installed in order for the login to work? 我的问题是:我真的需要安装Facebook应用程序才能使登录正常工作吗?
Facebook app is not necessarily needed as you can also proceed through web widget login. 不一定需要Facebook应用,因为您也可以通过Web小部件登录进行操作。 However, when you are a developer, you need to take care of key-hash pair when you generate signed apk.
但是,当您是开发人员时,在生成签名的apk时需要注意密钥哈希对。 to keep both ways (applogin and web widget login) available, use this..
要保持两种方式(applogin和Web小部件登录)可用,请使用此方法。
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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.