Android上的Facebook Unity SDK - 安装FB App时登录失败 [英] Facebook Unity SDK on Android - Login fails when FB App installed

查看:180
本文介绍了Android上的Facebook Unity SDK - 安装FB App时登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有与此问题中讨论的相同的问题:
Facebook在Android上的Unity SDK - 从FB.Login回调的麻烦



在Android上,当安装了普通的Facebook应用程序,使用Unity SDK调用FB.Login(),提示用户接受应用程序的权限,当应用程序被批准时,回调将触发:
FBResult.Text



{is_logged_in:false,user_id:,access_token:}



FBResult.Error



null



当安装了Facebook应用程序时,使用Web流程并且正常工作,但是我尝试使用Unity SDK的v4.2.4和v4.2.2。



/ p>

编辑:还应该注意,我已经在2种不同的设备(Galaxy Note 10.1和Nexus 7)



提前感谢






在某些情况下,问题很简单,您已经忘记了developers.facebook上的设置。 Brian在这里用图片解释: http ://answers.unity3d.com/questions/543540/facebook-sdk-v424-android-login-not-working.html 对于没有fb应用程序的设备,它会很容易地工作(!),如果你完全忘记了设置。对于实际的问题,幸运的是有一个解决方案,即使你在Mac上使用Unity,它很简单: http://answers.unity3d.com/questions/609810/using-facebook-api-with-android -says-login-is-canc.html

解决方案

Ach感觉如此愚蠢,最终设法自己解决通过部署到中介Google Android Project,我能够使用logcat来获取更有用的错误消息:


remote_app_id不匹配存储的ID


从那里我发现这个主题涉及标准的Android SDK:
Android Facebook SDK 3.0提供了remote_app_id与存储ID不符吨;同时登录



最后通过将代码片段替换为密钥哈希来解决问题

  try {
PackageInfo info = getPackageManager()。getPackageInfo(
com.facebook.samples.loginhowto,PackageManager.GET_SIGNATURES);
(签名签名: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){
}

用您自己的包名替换com.facebook.samples.loginhowto



资料来源:
https://stackoverflow.com/a/14421260/2823496



通过命令行或通过Unity取得正确的keyhash,取决于是否安装了正确版本的openssl(并存储在PATH中),但不知道是什么版本。 (尝试了一个链接的答案)所以,直到任何人努力与这个。






注意 - 几乎不可能如果您使用Mac进行Unity开发,请执行此操作。幸好简单的解决方案是这样的: http://answers.unity3d.com/questions/609810/using-facebook-api-with-android-says-login-is-canc.html


I appear to be having the same issue as discussed in this question: Facebook SDK for Unity on Android - Trouble about callback from FB.Login

On Android when the regular Facebook app is installed, calls to FB.Login() using the Unity SDK prompt the user to accept permissions for the app and when the app is approved the callback is fired with: FBResult.Text

{"is_logged_in":false,"user_id":"","access_token":""}

FBResult.Error

null

When the Facebook app is installed the web flow is used and works fine, I have however tried this with v4.2.4 and v4.2.2 of the Unity SDK.

Any other advice on getting this resolved?

EDIT: Should also note, I've tried this on 2 different devices (Galaxy Note 10.1 and Nexus 7)

Thanks in advance!


A note for 2014. In some cases the problem is very simply that you've forgotten the settings on developers.facebook. Brian explains it here with images: http://answers.unity3d.com/questions/543540/facebook-sdk-v424-android-login-not-working.html Confusingly it WILL WORK (!) on devices WITHOUT the fb app, if you have completely forgotten the settings. As to the actual problem, fortunately there is a solution even if you are using Unity on Mac and it is simple: http://answers.unity3d.com/questions/609810/using-facebook-api-with-android-says-login-is-canc.html

解决方案

Ach feel so silly, eventually managed to solve it myself, by deploying to an intermediary Google Android Project, I was able to use logcat to obtain a more useful error messsage:

remote_app_id does not match stored id

From there I found this topic relating to the standard Android SDK: Android Facebook SDK 3.0 gives "remote_app_id does not match stored id" while logging in

And finally solved the problem by replacing the Key Hash with the one obtained by this code snippet

try {
PackageInfo info = getPackageManager().getPackageInfo(
      "com.facebook.samples.loginhowto", 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) {
}

Replacing com.facebook.samples.loginhowto with your own package name of course

Source: https://stackoverflow.com/a/14421260/2823496

It seems getting the correct keyhash, via command line or through Unity depends on having the right version of openssl installed (and stored in PATH) but no idea what version that is. (tried the one in linked answer) So heads up to anyone else struggling with this.


Note - it's almost impossible to do this if you're using Mac for Unity development. Here's the fortunately simple solution in that case http://answers.unity3d.com/questions/609810/using-facebook-api-with-android-says-login-is-canc.html

这篇关于Android上的Facebook Unity SDK - 安装FB App时登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆