简体   繁体   English

PhoneGap添加Facebook Connect插件

[英]PhoneGap add Facebook Connect plugin

I want to add com.phonegap.plugins.facebookconnect to my PhoneGap build android app but I unable to do it. 我想将com.phonegap.plugins.facebookconnect添加到我的PhoneGap构建android应用程序中,但我做不到。 In doc site they say to add 他们说在文档站点中添加

<gap:plugin name="com.phonegap.plugins.facebookconnect">
    <param name="APP_ID" value="..." />
    <param name="APP_NAME" value="..." />
</gap:plugin>

in config.xml file but there is 3 config.xml files in PhoneGap build folder and even when I add it what than? config.xml文件中,但是PhoneGap构建文件夹中有3个config.xml文件,即使我添加它,还有什么? There should be files added to project like cdv-plugin-fb-connect.js and facebook-js-sdk.js so I can include them in index.html but none of files are added to project. 应该将诸如cdv-plugin-fb-connect.jsfacebook-js-sdk.js之类的文件添加到项目中,以便我可以将它们包括在index.html中,但是没有文件添加到项目中。 How can I manage that? 我该如何处理?

Answer below is for phonegap-build. 以下答案是关于phonegap-build的。 Disregard. 漠视。

  1. Add the below to your config.xml and ensure you place your config.xml in the root folder with your index.html file: 将以下内容添加到config.xml中,并确保将config.xml和index.html文件放在根文件夹中:

     <gap:plugin name="com.phonegap.plugins.facebookconnect"> <param name="APP_ID" value="..." /> <param name="APP_NAME" value="..." /> </gap:plugin> 
  2. Add the below to the <head></head> of your index.html file and every .html file that you want to access the plugin scripts: 将以下内容添加到index.html文件和要访问插件脚本的每个.html文件的<head></head>中:

     <script scr="phonegap.js"></script> <script src="cdv-plugin-fb-connect.js"></script > <script src="facebook-js-sdk.js"></script > 
  3. Read and follow the documentation located here . 阅读并遵循此处的文档。 Be sure to pay attention to the paragraph titled "Facebook Requirements and Set-Up". 确保注意标题为“ Facebook要求和设置”的段落。

  4. Once complete, upload your zipped project to build.phonegap.com and wait for your project to be compiled. 完成后,将压缩后的项目上传到build.phonegap.com,然后等待项目被编译。

Notes: 笔记:

  • You should only have 1 config.xml file in the root of your project. 您的项目根目录中应该只有1个config.xml文件。
  • Do not add the phonegap.js, cdv-plugin-fb-connect.js file or facebook-js-sdk.js files to the root of your project. 不要将phonegap.js,cdv-plugin-fb-connect.js文件或facebook-js-sdk.js文件添加到项目的根目录。 Phonegap Build will handle that for you. Phonegap Build将为您处理。

@Dom I did step by step how you specified: 1. added to config.xml in platforms/android/assets/www/config.xml 2. included js files in header and when I execute phonegap install android from cmd with this code: @Dom我逐步说明了如何指定:1.添加到platform / android / assets / www / config.xml中的config.xml中。2.头文件中包含js文件,当我执行phonegap install android时,使用以下代码从cmd phonegap install android

document.addEventListener('deviceready', function() {
alert('1');
  FB.init({
      appId: 'appid',
      nativeInterface: CDV.FB,
      useCachedDialogs: false
  });
  alert('2');

  FB.getLoginStatus(handleStatusChange);
  alert('3');

  authUser();
  updateAuthElements();
  alert('4');
});

it only displays first alert and removes .js files from heder. 它仅显示第一个警报,并从提示中删除.js文件。 Why is that happening? 为什么会这样呢? - It was happening because when you edit in phonegap build you don't edit in platforms/adnroid/assets/www but in root folder of project there is www folder and you edit config.xml and index.html there and after running app it is build for android from there. -发生这种情况的原因是,当您在phonegap版本中进行编辑时,您没有在platform / adnroid / assets / www中进行编辑,但是在项目的根文件夹中有www文件夹,并且您在其中运行config.xml和index.html后对其进行编辑是从那里为android构建的。

Edit: I have just wrapped FB.init in try/catch and I got this error : ReferenceError FB is not defined I think that is because js is not loading. 编辑:我刚刚将FB.init包装在try / catch中,但出现此错误: ReferenceError FB is not defined我认为这是因为js未加载。

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

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