Facebook登录使用Parse始终返回user.isNew()假的Android [英] Facebook login with Parse always returns false in user.isNew() Android
问题描述
我用解析Android中的Facebook登录的问题。
一切工作正常,但我总是得到用户通过Facebook登录。
我发现了同样的问题,一个人在这里<一个href=\"https://stackoverflow.com/questions/25334873/facebook-login-not-working-properly-parse\">Facebook登录工作不正常(解析)但对我来说他的回答不工作。
列表&LT;串GT;权限= Arrays.asList(电子邮件);
ParseFacebookUtils.logIn(权限,getActivity(),新LogInCallback(){
@覆盖
公共无效完成(ParseUser用户,ParseException的错误){ 如果(用户== NULL){
Log.d(WelcomeMainFragment
嗯哦用户取消了Facebook登录); }否则如果(user.isNew()){
Log.d(WelcomeMainFragment
用户注册了,并通过Facebook登录!);
}其他{
Log.d(WelcomeMainFragment
用户登录通过Facebook!);
}
}
});
user.isNew()
总是返回假的!即使在我的应用程序的新Facebook的帐户。
我需要有工作是否新款()方法,能在code的该块创建解析用户的第一次。
非常感谢。
经过一番研究,我发现了什么问题。
基本上,我有两个问题:
- 我没有得到正确的密钥散列。
密钥工具-exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore
YOUR_RELEASE_KEY_PATH | OpenSSL的SHA1 -binary | OpenSSL的BASE64
块引用>做上述我得到了错误的密钥散列。所以,我鼓励你这块code,以获得它:
{尝试
PackageInfo信息= getPackageManager()。getPackageInfo(
your.package.name
PackageManager.GET_SIGNATURES);
对(签字签名:info.signatures){
消息摘要MD = MessageDigest.getInstance(SHA);
md.update(signature.toByteArray());
Log.d(KeyHash:Base64.en codeToString(md.digest(),Base64.DEFAULT));
}
}赶上(ē的NameNotFoundException){
}赶上(抛出:NoSuchAlgorithmException E){
}
块引用>您在调试和生产执行它得到这两个键。
<醇开始=2>最重要的问题是,我不得不允许解析Facebook的身份验证和包括Facebook应用程序ID和应用程序的秘密。你可以做,去设置>身份验证>的Facebook。 我希望可以帮助别人。
I have an issue with Facebook login in Android using Parse. Everything is working fine but I always get User logged in through Facebook.
I found a guy with the same problem here Facebook Login not working properly (Parse) but his answer doesnt work for me.
List<String> permissions = Arrays.asList("email"); ParseFacebookUtils.logIn(permissions, getActivity(), new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { if (user == null) { Log.d("WelcomeMainFragment", "Uh oh. The user cancelled the Facebook login."); } else if (user.isNew()) { Log.d("WelcomeMainFragment", "User signed up and logged in through Facebook!"); } else { Log.d("WelcomeMainFragment", "User logged in through Facebook!"); } } });
user.isNew()
always returns false! even with new facebooks accounts in my app. I need to have working isNew() method to be able to create parse users for first time in that block of code.Thanks a lot.
解决方案After some research I found what the problem was. Basically I had two problems:
- I wasn't getting the key hash properly.
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64
Doing above I was getting the wrong key hash. So I encourage you to get it with this piece of code:
try { PackageInfo info = getPackageManager().getPackageInfo( "your.package.name", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { }
You have to execute it in debug and production to get both keys.
- The most important problem was that I had to allow Facebook authentication on Parse and include the Facebook app id and app secret. You can do that going to Settings > Authentication > Facebook.
I hope that can help someone.
这篇关于Facebook登录使用Parse始终返回user.isNew()假的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!