简体   繁体   English

如果未安装应用程序,Facebook登录将不起作用

[英]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.

相关问题 Android,安装Facebook应用程序后Facebook登录不起作用 - Android, Facebook login doesn't work when the Facebook application is installed Facebook登录:它不会重定向到已安装的Facebook应用程序吗? - Facebook Login: It doesn't redirect to the Facebook app installed? 如果未安装应用程序,则Facebook登录无法启动第二个活动 - Facebook login doesn't start second activity if app is not installed 没有Facebook应用的Android Facebook SDK 4登录无法正常工作 - Android Facebook SDK 4 login without Facebook app doesn't work Android Facebook登录在调试中工作,在发布的应用程序中不起作用 - Android Facebook login works in debug, doesn't work in published app 如果从Google Play下载应用程序,则Facebook登录不起作用 - Facebook login doesn't work if app is downloaded from google play 安装FB应用程序时,Android Facebook示例应用程序无法登录 - Android Facebook sample app doesn't login when FB app installed Facebook登录不适用于Facebook App - Facebook login don't work with facebook app 如果在模拟器上安装了Facebook应用,则无法登录到Facebook-Android 4.3 - Login to facebook does not work if facebook app is installed on emulator - Android 4.3 我的设备上安装了Facebook应用后,我的应用无法正常工作 - My app doesn't work when facebook app is installed in my device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM