应用程序为 Facebook 登录配置错误:Android Facebook 集成问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12382558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
App is misconfigured for Facebook login: Android Facebook integration issue
提问by Arun Badole
I have integrated my application with Facebook, and for this I am using Facebook's Graph API. I am retrieving profile and friends information. It is working fine on my device which has Android 2.3(Gingerbread), but recently my client has faced an issue while he is trying to connect to Facebook through my app. He has Android 4.0(Ice Cream Sandwich) on his device. When he clicks a button on the app that takes him to the Facebook login screen, after login he gets a message:
我已将我的应用程序与 Facebook 集成,为此我使用 Facebook 的Graph API。我正在检索个人资料和朋友信息。它在我装有Android 2.3(Gingerbread) 的设备上运行良好,但最近我的客户在尝试通过我的应用程序连接到 Facebook 时遇到了一个问题。他的设备上装有Android 4.0(冰淇淋三明治)。当他点击应用程序上的按钮进入 Facebook 登录屏幕时,登录后他会收到一条消息:
My app is misconfigured for Facebook login. Press Okay to go back to the application without connecting to Facebook.
我的应用程序配置错误,无法登录 Facebook。按确定返回应用程序,无需连接到 Facebook。
I am not getting what is the problem whether it is related to Android version or what.
我不知道问题是与 Android 版本还是什么有关。
How can I fix this problem?
我该如何解决这个问题?
回答by Jesse Chen
I work at Facebook, and this is an important issue that needs to be addressed. The other answer for this question suggests that disabling SSO is very bad and will open up your app to malicious apps that can steal your user's Facebook credentials.
我在 Facebook 工作,这是一个需要解决的重要问题。这个问题的另一个答案表明禁用 SSO 非常糟糕,并且会将您的应用程序打开给恶意应用程序,这些应用程序可以窃取您用户的 Facebook 凭据。
The hack launches a WebView dialog to Facebook without SSO, and the user must type their login credentials into that dialog. Malicious apps can then steal this information easily. It is always advised to implement Facebook SSO correctly to ensure that your app is secure and protect your user's sensitive data.
该黑客在没有 SSO 的情况下向 Facebook 启动了一个 WebView 对话框,并且用户必须在该对话框中输入他们的登录凭据。恶意应用程序可以轻松窃取此信息。始终建议正确实施 Facebook SSO,以确保您的应用程序安全并保护您用户的敏感数据。
Prior to adding this error message, the dialog would automatically close without warning and fail silently. We added this error message to visually display that there is an issue with your app configuration in your Facebook app dashboard. For Android, if you check your LogCat, you'll see that after pressing "Okay", there should be an error message that will display a more technical description of what is causing the authentication to fail.
在添加此错误消息之前,对话框将在没有警告的情况下自动关闭并静默失败。我们添加了此错误消息,以直观地显示您的 Facebook 应用仪表板中的应用配置存在问题。对于 Android,如果您检查您的LogCat,您会看到在按“确定”后,应该会出现一条错误消息,其中将显示导致身份验证失败的更多技术说明。
For example, if you use our Hackbook example and did not supply your own APP_ID in the source and did not add your hash key to the dashboard, you'll see this error in LogCat after pressing "Okay" in the native SSO dialog (if Util.ENABLE_LOG is set to true):
例如,如果您使用我们的 Hackbook 示例并且没有在源代码中提供您自己的 APP_ID 并且没有将您的哈希键添加到仪表板,那么在本机 SSO 对话框中按“确定”后,您将在 LogCat 中看到此错误(如果Util.ENABLE_LOG 设置为 true):
D/Facebook-authorize(24739): Login failed: invalid_key:Android key mismatch. Your key "uk3udeH7vrOGNFH2FJjdJbdWJWI" does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers
D/Facebook-authorize(24739):登录失败:invalid_key:Android 密钥不匹配。您的密钥“uk3udeH7vrOGNFH2FJjdJbdWJWI”与您的应用程序设置中指定的允许密钥不匹配。在http://www.facebook.com/developers检查您的应用程序设置
We added the visual error message to help you. This, in theory, does not break previous implementations if it was implemented correctly to begin with. If you see this error message, that means you did not configure your app settings correctly on your dashboard.
Double check your Android Class/Package name, Android hash keys, etc. You will not see this message if you did everything correctly.
我们添加了视觉错误消息来帮助您。理论上,如果从. 如果您看到此错误消息,则表示您没有在仪表板上正确配置应用程序设置。
仔细检查您的 Android 类/包名称、Android 哈希键等。如果您正确执行所有操作,您将不会看到此消息。
In summary, you are getting that error message because there is an issue with your app configuration, for example, a mismatch between the Android hash keys in your dashboard. Before Facebook added this error message, the dialog would launch, then automatically close and fail. To fix this, check your LogCat for any error messages and make sure that you have everything implemented correctly. You can read up on our documentationto make sure you have everything correct. Do not use the accepted answer for this question.
总之,您收到该错误消息是因为您的应用程序配置存在问题,例如,仪表板中的 Android 哈希键不匹配。在 Facebook 添加此错误消息之前,对话框将启动,然后自动关闭并失败。要解决此问题,请检查您的 LogCat 是否有任何错误消息,并确保您已正确实施所有内容。您可以阅读我们的文档以确保一切正确。对于这个问题,不要使用公认的答案。
You can also follow the external bug reportthat a Facebook developer has reported for more updates.
回答by pandabear
Try to set it like this:
尝试这样设置:
First download OpenSSL(if you have a 64-bit machine you must download openssl-0.9.8e X64, not the latest version, openssl-0.9.8k X64, because the output will not be valid). Extract your files, create the folder openssl
, for example in C:/ and copy files there.
首先下载OpenSSL(如果您有 64 位机器,则必须下载openssl-0.9.8e X64,而不是最新版本 openssl-0.9.8k X64,因为输出将无效)。提取您的文件,创建文件夹openssl
,例如在 C:/ 中并在那里复制文件。
Find your path to keytoo. Mine is C:\Program Files\Java\jdk1.7.0_05\bin.
找到通往 keyto 的道路。我的是 C:\Program Files\Java\jdk1.7.0_05\bin。
Find your path to debug.keystore
. YHou can see what is path if you open in Eclipse, menu Window-> Preferences-> Android-> Build, and you will see Default Debug keystore:-and the path.
找到你的路径debug.keystore
。如果您在 Eclipse 中打开,您可以看到路径是什么,菜单Window-> Preferences-> Android-> Build,您将看到Default Debug keystore:- 和路径。
Find your path to openssl
. Mine is C:\openssl8e\bin/.
找到你的路径openssl
。我的是 C:\openssl8e\bin/。
Open cmd and type:
打开cmd并输入:
"C:\Program Files\Java\jdk1.7.0_05\bin\keytool" -exportcert -alias androiddebugkey -keystore "C:\Users\User.android\debug.keystore" | "C:\openssl8e\bin\openssl" sha1 -binary | "C:\openssl8e\bin\openssl" base64
"C:\Program Files\Java\jdk1.7.0_05\bin\keytool" -exportcert -alias androiddebugkey -keystore "C:\Users\User.android\debug.keystore" | "C:\openssl8e\bin\openssl" sha1 -binary | "C:\openssl8e\bin\openssl" base64
Aand then press Enter.
A然后按Enter。
Insert password: android
插入密码: android
You will get your hash key for debug.keystore
.
您将获得debug.keystore
.
When you export a signed APK, and you create a keystore for the application, just replace in cmd debugkeystore alias with your alias for the app, the keystore path with the path to your newly created keystore for the app and insert the password for your app.keystore
, and you will get a new hash key for your signed app.
当您导出已签名的APK并为应用程序创建密钥库时,只需将 cmd debugkeystore 别名替换为您的应用程序别名,密钥库路径与您新创建的应用程序密钥库的路径并插入密码app.keystore
,您将获得一个新的已签名应用程序的哈希密钥。
回答by Reijo Korhonen
The answer from Jesse Chen is fine. Facebooks SDK works fine, don't break it.
Jesse Chen的回答很好。Facebooks SDK 工作正常,不要破坏它。
I again ran into this problem and found out that the Facebook SDK documentation is corrected and is very fine now. Now it is guiding how to debug and release hash keys can be set; just do as it says.
我再次遇到这个问题,发现 Facebook SDK 文档已更正,现在非常好。现在正在指导如何调试和发布可以设置的哈希键;按照它说的做。
Below is my old story. There is missing that you can set two hash keys, one for debugging and one for signed, released application for the old Play Store.
下面是我的旧故事。缺少的是您可以设置两个哈希键,一个用于调试,另一个用于旧Play Store 的签名、发布的应用程序。
I found out that problem wasin my case in the Facebook SDK's documentation. It guided us to use the debug key hash and put it in Facebook's app configuration. Hash is guided to get this way:
我发现这个问题是在我的Facebook的SDK文档中的情况。它指导我们使用调试密钥哈希并将其放入 Facebook 的应用程序配置中。哈希被引导以这种方式获得:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
This works fine, when you are dubugging or running application from Eclipse.
当您从Eclipse调试或运行应用程序时,这很好用。
But, if you publish your application to Andoid Play, you must use your own publisher key to export the signed .apk file. With that .apk, the hash in the Facebook app console is not valid any more! You must get a hash for the developer key like this:
但是,如果您将应用程序发布到 Andoid Play,则必须使用您自己的发布者密钥来导出已签名的 .apk 文件。使用该 .apk,Facebook 应用程序控制台中的哈希不再有效!您必须像这样获取开发人员密钥的哈希值:
keytool -exportcert -alias <developer alias> -keystore ~/.android/<developer keystore> | openssl sha1 -binary | openssl base64
And put it in the Android Key Hash in the Facebook app console for your published application. After that, SSO works fine again for your signed .apk file.
并将其放入 Facebook 应用程序控制台的 Android Key Hash 中,用于您发布的应用程序。之后,SSO 再次对您签名的 .apk 文件工作正常。
回答by rmcc
From what I could gather, it's a Facebook problem and has been reported. But, the problem persists.
据我所知,这是 Facebook 的问题,已被举报。但是,问题仍然存在。
A way around this (tested on 2.3.3) is to hack on the Facebook SDK, seach for the 2 authorizemethods and change the DEFAULT_AUTH_ACTIVITY_CODEto FORCE_DIALOG_AUTH. This will disable the Single Sign On feature.
解决此问题的一种方法(在 2.3.3 上测试)是破解 Facebook SDK,搜索 2 种授权方法并将DEFAULT_AUTH_ACTIVITY_CODE更改为FORCE_DIALOG_AUTH。这将禁用单点登录功能。
If your prefer got to
如果您愿意
public void authorize(Activity activity, String[] permissions,
int activityCode, final DialogListener listener)
and disable the startSingleSignOnpart. It's preferable not to, because eventually Facebook will solve the problem, and you only have to put the old constant back.
并禁用startSingleSignOn部分。最好不要,因为最终 Facebook 会解决这个问题,而你只需要把旧的常量放回去。
EDIT
编辑
This solution raises security problems. Check Jesse Chen answer.
该解决方案引发了安全问题。检查 Jesse Chen 的答案。
回答by 9to5ios
I faced the same problem, after spending 24 hours and a lot of search we use this method to solve my problem.
我遇到了同样的问题,在花了 24 小时和大量搜索之后,我们使用这种方法来解决我的问题。
Check your Xcode project current bundle identifier for example : com.yourcompanyname.yourappname
use the same com.yourcompanyname.yourappname bundle identifier for creating app in Facebook see attachment.
检查您的 Xcode 项目当前包标识符,例如:com.yourcompanyname.yourappname
使用相同的 com.yourcompanyname.yourappname 捆绑标识符在 Facebook 中创建应用程序,请参阅附件。
回答by haupman
I had this problem just a few minutes ago myself on 4.0.4 and it seems to have resolved itself.
几分钟前我自己在 4.0.4 上遇到了这个问题,它似乎已经解决了。
回答by Nitin Bansal
Although late, still useful: *Here's the corerct way to do(for debug key, change accordingly for release):*
虽然晚了,但仍然有用:*这是正确的方法(对于调试键,相应地更改以发布):*
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\<User>\.android\debug.keystore" > <Drive letter>:\debug.txt
openssl sha1 -binary "<Drive letter>:\debug.txt" > "<Drive letter>:\debug_sha.txt"
openssl base64 -in "<Drive letter>:\debug_sha.txt" > "<Drive letter>:\debug_base64.txt"
The hash is in the last generated file: debug_base64.txt....open it and copy the hash.
散列在最后生成的文件中:debug_base64.txt....打开它并复制散列。
Remember to replace "" and with your username and drive letter of your choice
请记住将 "" 和您选择的用户名和驱动器号替换
回答by gnobal
When you create the key hash, you might end up with something which has the equality sign "=" at the end, like ga0RGNYHvNM5d0SLGQfpQWAPGJ8=. While Facebook gladly accepts the equality sign as part of the key hash, you have to remove it in order for it to work.
当您创建密钥散列时,您可能会得到末尾带有等号“=”的内容,例如ga0RGNYHvNM5d0SLGQfpQWAPGJ8=。虽然 Facebook 很乐意接受等号作为密钥散列的一部分,但您必须将其删除才能使其正常工作。
Additionally, check out the accepted answer to Android Facebook SDK 3.0 gives "remote_app_id does not match stored id" while logging in: when getting the key hash for the debug keystore, use the password "android". Otherwise the key hash will be incorrect and you will get the error specified in the question (be nice and vote up the answer there if it helped you.)
此外,请查看Android Facebook SDK 3.0的已接受答案,在登录时给出“remote_app_id 与存储的 id 不匹配”:获取调试密钥库的密钥哈希时,请使用密码“android”。否则,密钥散列将不正确,您将收到问题中指定的错误(如果对您有帮助,请在那里投票并投票。)
回答by laaptu
On Debian system like ubuntu use the keytool
of java
found under directory /usr/lib/jvm/jdk*.*.*/bin/keytool
and generate like this
在像 ubuntu 这样的 Debian 系统上,使用在目录keytool
下java
找到的of /usr/lib/jvm/jdk*.*.*/bin/keytool
并像这样生成
/usr/lib/jvm/jdk1.7.0/bin/keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
This way you get the authentic hash key that can be put under your app hash of facebook.
通过这种方式,您可以获得可以放在您的 facebook 应用程序哈希下的真实哈希键。
回答by Niklas Mencke
Regarding apps signed with OWN keystore: After spending several hours solving this issue, I finally got it and want to provide an answer for those who are still suffering:
关于使用 OWN 密钥库签名的应用程序:在花了几个小时解决这个问题后,我终于明白了,并希望为那些仍在受苦的人提供答案:
My steps: I signed my app via eclipse with my own keystore file (NOT debug.keystore). Via command line and known commands (keytool -exportcert -alias -keystore ~/.android/ | openssl sha1 -binary | openssl base64) I successfulluy received the key hash. Pasted the key hash in the dev dashboard,waited a few mins -> Still the same ERROR (as specified in the question above). i tried several differend keytools, on several jdks, etc... nothing changed.
我的步骤:我通过 eclipse 使用我自己的密钥库文件(不是 debug.keystore)签署了我的应用程序。通过命令行和已知命令(keytool -exportcert -alias -keystore ~/.android/ | openssl sha1 -binary | openssl base64)我成功地收到了密钥哈希。将密钥哈希粘贴到开发仪表板中,等了几分钟 -> 仍然是相同的错误(如上述问题中所述)。我尝试了几个不同的 keytools,在几个 jdks 上,等等......没有任何改变。
Solution:
I turned on debuggable in manifest, turned on debugging in facebook sdk. then i signed the apk with my own keystore and uploaded it on real device.
i connected device via usb and opened DDMS perspective to see logcat on device.
I started my app and let the error message occur.
It prints out a key totally different from the key generated by keytool. I took this key from logcat, pasted it to dev dashboard and voila -> EVERYTHING WORKS
解决方案:我在 manifest 中打开了 debuggable,在 facebook sdk 中打开了调试。然后我用我自己的密钥库签署了 apk 并将其上传到真实设备上。我通过 USB 连接设备并打开 DDMS 透视图以查看设备上的 logcat。
我启动了我的应用程序并让错误消息出现。它打印出一个与 keytool 生成的密钥完全不同的密钥。我从 logcat 拿到了这个密钥,将它粘贴到开发仪表板,瞧 -> 一切正常
I still don't know why this happens or what is causing the wrong key, but this way it works for me.
我仍然不知道为什么会发生这种情况或导致错误密钥的原因,但这种方式对我有用。