简体   繁体   English

Cordova / Phonegap:无法让Facebook Phonegap插件工作

[英]Cordova/Phonegap: Can't get Facebook Phonegap plugin to work

I tried creating a Cordova/Phonegap app and adding the Facebook plugin, but alert(typeof facebookConnectPlugin); 我尝试创建一个Cordova / Phonegap应用程序并添加Facebook插件,但警告(ty​​peof facebookConnectPlugin); shows undefined: 显示未定义:

sudo npm install -g cordova
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add ios
cordova -d plugin add https://github.com/phonegap/phonegap-facebook-plugin --variable APP_ID="1415347585409217" --variable APP_NAME="Test"
vi www/index.html  # Add: alert(typeof facebookConnectPlugin); to the last <script>
cordova emulate ios

Expected: The emulator shows "Object" in the alert dialog. 预期:模拟器在警告对话框中显示“对象”。

Actual: The emulator shows "undefined" in the alert dialog. 实际:模拟器在警告对话框中显示“未定义”。

Anyone know what I am doing wrong? 谁知道我做错了什么?


UPDATE: Thanks to Devgeeks for his answer below. 更新:感谢Devgeeks的回答如下。

Here are a couple of other things I needed to do to get it working: 以下是我需要完成的其他一些工作:

1) Install the newer "develop" branch of the plugin: 1)安装插件的较新“开发”分支:

cordova -d plugin add "https://github.com/phonegap/phonegap-facebook-plugin#develop" --variable APP_ID="1415347585409217" --variable APP_NAME="Test"

2) Add the following below the opening tag: 2)在开始标记下面添加以下内容:

<!-- fb-root is needed by the FB API. -->
<div id="fb-root"></div>

3) If you want FB login to work in the browser (for testing), copy www/js/facebookConnectPlugin.js into your app. 3)如果您希望FB登录在浏览器中工作(用于测试),请将www / js / facebookConnectPlugin.js复制到您的应用程序中。 Then include it before the closing tag: 然后在结束标记之前包含它:

<script src="facebookConnectPlugin.js"></script>

Then add the following to your section: 然后将以下内容添加到您的部分:

<script>
  window.fbAsyncInit = function () {
      if (!window.cordova) {
        // Initialize - only executed when testing in the browser.
        facebookConnectPlugin.browserInit(308939305080);
      }
  }
</script>

If you get "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.", edit facebookConnectPlugin.js and change sdk.js to sdk/debug.js . 如果你得到“应用程序配置不允许给定URL:应用程序的设置不允许一个或多个给定的URL。它必须与网站URL或Canvas URL匹配,或者域必须是其中一个的子域应用程序的域。“,编辑facebookConnectPlugin.js并将sdk.js更改为sdk / debug.js。

4) If you get the following while building the app for Android: 4)如果您在构建Android应用程序时获得以下内容:

sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var

try running the following (from Issue 432 ): 尝试运行以下命令(来自问题432 ):

cp platforms/android/local.properties platforms/android/FacebookLib

Add: alert(typeof facebookConnectPlugin); to the last <script>

That is behaving as expected, believe it or not. 无论信不信,这表现得像预期的那样。

Plugins are not available till the deviceready event has fired: http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready deviceready事件触发之前,插件不可用: httpdeviceready

Try checking for the facebookConnectPlugin in the onDeviceReady of the generated www/js/index.js instead of an immediately fired tag? 尝试检查生成的www/js/index.jsonDeviceReady中的facebookConnectPlugin而不是立即触发的标记?

大家好,我已经找到了一些新的Facebook集成在手机间隙应用程序,没有任何Facebook插件,你可以使用Facebook功能,为此使用phonegap.facebook.inappbrowser.js使用此js你可以轻松访问所有Facebook功能更多信息访问此URL: 没有任何插件的Facebook集成步骤

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM