android - Phonegap Cordova 使用 Facebook 登录
问题描述
我是 Phonegap 的新手,我正在尝试在我的 Cordova 应用程序中添加 Facebook 登录,我尝试了 Plugin 和 Facebook SDK for Javascript。
插件:https ://github.com/jeduan/cordova-plugin-facebook4
Facebook JavaScript SDK:https ://developers.facebook.com/docs/facebook-login/web
在 sdk 和 javascript 插件中,我都遇到了困难。
插入:
The key hash does not match any stored key hashes
Facebook SDK JS:
Unable to load URL: The domain for this URL is not included in the application domains. In order to load this URL, add all domains and subdomains to the Application Domains field in the application settings.
我尝试将 localhost 添加为我的域但不起作用,并尝试在 Windows 中创建哈希,我生成了哈希并将其添加到我的 facebook 应用程序中,但仍然出现相同的错误。
有人有想法吗?
<!--Version Phonegap-->
<preference name="cordova-ios" version="4.5.4" />
<preference name="phonegap-version" value="cli-8.0.0" />
Facebook 插件 config.xml:
<plugin name="cordova-plugin-facebook4" spec="~4.2.1">
<variable name="APP_ID" value="XXXXXXXXX" />
<variable name="APP_NAME" value="YYYYYY" />
</plugin>
Facebook插件登录:
const permissions = new Array("email","public_profile");
facebookConnectPlugin.login(permissions, function (userData) {
console.log("UserInfo: ", userData);
},
function loginError(error) {
console.error(error)
}
);
Facebook SDK JS:
FB.login(function (response) {
if (response.status === 'connected') {
// Logged into your app and Facebook.
} else {
// The person is not logged into this app or we are unable to tell.
}
});
解决方案
我找到了解决方法:
The key hash does not match any stored key hashes
我将我的 Facebook 应用程序设置为 Android 平台并使用 (config.xml) 设置我的包名称:
widget id="com.XXXX.YYY.ZZZ"
还有我的类名,我遵循这个并使用了http://www.javadecompilers.com/result。
为了生成我的哈希,我遵循Muhammad Omar ElShourbagy 解决方案。
一切正常。
推荐阅读
- kotlin - 从辅助构造函数调用 SuperConstructor
- node.js - npm install 在我的角度项目中不起作用
- angularjs - 如何在一个解决方案中配置捆绑和缩小两个项目,如管理员和用户?
- java - 如何动态设置 SequenceGenerator allocationSize?
- javascript - 将 JSON 中的特殊字符转换为 CSV (excel) 时的字符编码
- amcharts4 - 如何在 amChart JS Radar 列系列图表中动态更改列宽和高度?
- ansible - 如何使用 json_query 从标准输出中提取带有 Ansible 的项目
- jquery - 使用 jQuery 在触控/移动设备上进行悬停交互
- excel - VBA循环将工作表中的单元格复制到主表中
- reactjs - 不从函数调用 getlocalstorage