Facebook Connect + jQuery Mobile + Phonegap 构建

2023-12-06

我试图了解如何使用脸书连接(登录)与jQuery 移动 and 音隙构建,但随着我搜索这些信息的次数越多,我就越感到困惑。

我已经在 Facebook 上创建了我的应用程序,并且我有 API 编号。

我不知道最好的方法是否是调用 PHP 页面(通过 ajax),其中通过 Facebook PHP SDK 或 Facebook SDK Javascript 验证 EMAIL + PASS。对于 SDK JS 我不明白如何将它集成到我的代码中(并且我不知道是否可以通过 localhost 测试它)。

如果有人能帮我解答这个问题...

Update

我尝试了@Dom 建议,但是当我单击按钮时,会发生任何操作。

下面是我的 HTML 代码:

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>Test</title>

    <!-- CSS -->
    <link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css">
    <link rel="stylesheet" href="css/codiqa.ext.css">

    <!-- jQuery and jQuery Mobile -->
    <script type="text/javascript" src="phonegap.js"></script>
    <script src="js/jquery-1.9.0.js"></script>
    <script src="js/utf8.js"></script>
    <script src="js/cdv-plugin-fb-connect.js"></script>
    <script src="js/facebook-js-sdk.js"></script>
    <script src="js/jquery.mobile-1.3.1.min.js"></script>
    <script>
            <!-- These are the notifications that are displayed to the user through pop-ups if the above JS files does not exist in the same directory-->
            if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
            if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
            if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');

            FB.Event.subscribe('auth.login', function(response) {
                               alert('auth.login event');
                               });

            FB.Event.subscribe('auth.logout', function(response) {
                               alert('auth.logout event');
                               });

            FB.Event.subscribe('auth.sessionChange', function(response) {
                               alert('auth.sessionChange event');
                               });

            FB.Event.subscribe('auth.statusChange', function(response) {
                               alert('auth.statusChange event');
                               });

            /*function getSession() {
                alert("session: " + JSON.stringify(FB.getSession()));
            }
            */
            function getLoginStatus() {
                FB.getLoginStatus(function(response) {
                                  if (response.status == 'connected') {
                                  alert('logged in');
                                  } else {
                                  alert('not logged in');
                                  }
                                  });
            }
            var friendIDs = [];
            var fdata;
            function me() {
                FB.api('/me/friends', { fields: 'id, name, picture' },  function(response) {
                       if (response.error) {
                       alert(JSON.stringify(response.error));
                       } else {
                       var data = document.getElementById('data');
                       fdata=response.data;
                       console.log("fdata: "+fdata);
                       response.data.forEach(function(item) {
                                             var d = document.createElement('div');
                                             d.innerHTML = "<img src="+item.picture+"/>"+item.name;
                                             data.appendChild(d);
                                             });
                       }
                    var friends = response.data;
                    console.log(friends.length); 
                    for (var k = 0; k < friends.length && k < 200; k++) {
                        var friend = friends[k];
                        var index = 1;

                        friendIDs[k] = friend.id;
                        //friendsInfo[k] = friend;
                    }
                    console.log("friendId's: "+friendIDs);
                       });
            }

            function logout() {
                FB.logout(function(response) {
                          alert('logged out');
                          });
            }

            function login() {
                FB.login(
                         function(response) {
                            if (response.session) {
                                alert('logged in');
                            } else {
                                alert('not logged in');
                            }
                        },
                         { scope: "email" }
                         );
            }


            function facebookWallPost() {
                console.log('Debug 1');
                var params = {
                    method: 'feed',
                    name: 'Facebook Dialogs',
                    link: 'https://developers.facebook.com/docs/reference/dialogs/',
                    picture: 'http://fbrell.com/f8.jpg',
                    caption: 'Reference Documentation',
                    description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
                  };
                console.log(params);
                FB.ui(params, function(obj) { console.log(obj);});
            }

            function publishStoryFriend() {
                randNum = Math.floor ( Math.random() * friendIDs.length ); 

                var friendID = friendIDs[randNum];
                if (friendID == undefined){
                    alert('please click the me button to get a list of friends first');
                }else{
                    console.log("friend id: " + friendID );
                    console.log('Opening a dialog for friendID: ', friendID);
                    var params = {
                        method: 'feed',
                        to: friendID.toString(),
                        name: 'Facebook Dialogs',
                        link: 'https://developers.facebook.com/docs/reference/dialogs/',
                        picture: 'http://fbrell.com/f8.jpg',
                        caption: 'Reference Documentation',
                        description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
                    };
                    FB.ui(params, function(obj) { console.log(obj);});
                }
            }

            document.addEventListener('deviceready', function() {
                                      try {
                                      alert('Device is ready! Make sure you set your app_id below this alert.');
                                      FB.init({ appId: "appid", nativeInterface: CDV.FB, useCachedDialogs: false });
                                      document.getElementById('data').innerHTML = "";
                                      } catch (e) {
                                      alert(e);
                                      }
                                      }, false);
            </script>
</head>
<body>
<div data-role="page" id="page_login">
    <div data-role="content" id="content-login">
        <div id="content">
            <a href="#" onclick="login()" data-role="button">Login Facebook</a>
            <a href="#" onclick="me()" data-role="button">Me</a>
            <a href="#" onclick="getLoginStatus()" data-role="button">Get Login Status</a>
            <a href="#" onclick="facebookWallPost()" data-role="button">facebookWallPost</a>
            <a href="#" onclick="publishStoryFriend()">friendstory</a>
        </div>
    </div>
</div>
</body>
</html>

XML代码:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns     = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "br.com.test"
        version   = "1.0.0">
    <name>Test</name>

    <!-- FB Connect Section -->
    <gap:plugin name="com.phonegap.plugins.facebookconnect">
        <param name="APP_ID" value="XXXXXXXXXX...." /> <!-- FB App ID-->
        <param name="APP_NAME" value="test" /> <!-- FB App Namespace-->
    </gap:plugin>

    <description>
        Test
    </description>

    <author href="http://test.com.br" email="[email protected]">
        Test
    </author>

    <gap:plugin name="com.phonegap.plugins.barcodescanner" />

    <feature name="http://api.phonegap.com/1.0/device" />

    <preference name="phonegap-version" value="2.9.0" />
    <preference name="orientation"      value="default" />
    <preference name="target-device"    value="universal" />
    <preference name="fullscreen"       value="false" />
    <preference name="webviewbounce"    value="true" />

    <icon src="icon.png" />
    <icon src="res/icon/android/icon-36-ldpi.png"   gap:platform="android"    gap:density="ldpi" />
    <icon src="res/icon/android/icon-48-mdpi.png"   gap:platform="android"    gap:density="mdpi" />
    <icon src="res/icon/android/icon-72-hdpi.png"   gap:platform="android"    gap:density="hdpi" />
    <icon src="res/icon/android/icon-96-xhdpi.png"  gap:platform="android"    gap:density="xhdpi" />
    <icon src="res/icon/blackberry/icon-80.png"     gap:platform="blackberry" />
    <icon src="res/icon/blackberry/icon-80.png"     gap:platform="blackberry" gap:state="hover"/>
    <icon src="res/icon/ios/icon-57.png"            gap:platform="ios"        width="57" height="57" />
    <icon src="res/icon/ios/icon-72.png"            gap:platform="ios"        width="72" height="72" />
    <icon src="res/icon/ios/icon-57-2x.png"         gap:platform="ios"        width="114" height="114" />
    <icon src="res/icon/ios/icon-72-2x.png"         gap:platform="ios"        width="144" height="144" />
    <icon src="res/icon/webos/icon-64.png"          gap:platform="webos" />
    <icon src="res/icon/windows-phone/icon-48.png"  gap:platform="winphone" />
    <icon src="res/icon/windows-phone/icon-173.png" gap:platform="winphone"   gap:role="background" />

    <gap:splash src="res/screen/android/screen-ldpi-portrait.png"  gap:platform="android" gap:density="ldpi" />
    <gap:splash src="res/screen/android/screen-mdpi-portrait.png"  gap:platform="android" gap:density="mdpi" />
    <gap:splash src="res/screen/android/screen-hdpi-portrait.png"  gap:platform="android" gap:density="hdpi" />
    <gap:splash src="res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:density="xhdpi" />
    <gap:splash src="res/screen/blackberry/screen-225.png"         gap:platform="blackberry" />
    <gap:splash src="res/screen/ios/screen-iphone-portrait.png"    gap:platform="ios"     width="320" height="480" />
    <gap:splash src="res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios"     width="640" height="960" />
    <gap:splash src="res/screen/ios/screen-ipad-portrait.png"      gap:platform="ios"     width="768" height="1024" />
    <gap:splash src="res/screen/ios/screen-ipad-landscape.png"     gap:platform="ios"     width="1024" height="768" />
    <gap:splash src="res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone" />
</widget>

  1. 查看位于的插件文档here.

  2. 确保您有以下内容<head>你的index.html:

    <script src="cdv-plugin-fb-connect.js"></script>
    <script src="facebook-js-sdk.js"></script>
    
  3. 确保您的 config.xml 包含以下内容:

    <gap:plugin name="com.phonegap.plugins.facebookconnect">
        <param name="APP_ID" value="..." />
        <param name="APP_NAME" value="..." />
    </gap:plugin>
    
  4. 最后,查看“简单示例”,了解如何使用位于here

希望这可以帮助。如果您仍然遇到问题,请发布一些您正在使用的代码供我们查看。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook Connect + jQuery Mobile + Phonegap 构建 的相关文章

随机推荐

  • 订阅事件时执行函数

    当有人订阅我在课堂上制作的事件时 是否可以执行一些代码 简短的说明 我需要配置一台外部电脑 以便在有人订阅此事件时向我发送数据 这样当收到该数据时 我可以抛出该事件 public class test public event EventH
  • Cos(90) 返回一个非常接近 0 的值,但我需要 0?

    temp x btm left 0 temp y btm left 1 的值 angle 90 Moving the bottom left coordinates btm left real temp x btm left cos ang
  • 需要工具提示:将Google Sheet现有数据更改为DataTable

    Problem 我看到的所有文档都使用 DataTable 将数据写入脚本本身 我需要从现有行调用此工具提示数据 我需要了解 HTML 页面和 google 工作表中嵌入图表之间的代码差异 Goal 我有一个需要自定义工具提示的散点图 我需
  • 使用预签名 URL 通过 cURL 将文件加载到 S3

    我获得了一个预签名 URL 用于在 S3 存储桶上上传文件 这是卷曲命令 curl v T dansero jpg https ss files dev s3 ap southeast 2 amazonaws com dansero jpg
  • 如何在Robot Framework中实现java库

    如何在 Eclipse 中创建库 然后将其导入 Robot FrameWork 中 我现在进行了很多搜索 但没有任何指南可以帮助我 您需要执行以下操作 创建您的 java 库 运行机器人框架jython版本时将其添加到类路径中 创建您的 j
  • 如果失败,请重试 SFTP?

    我正在使用 SSH NET 上传 但如果进程失败 我想重试 sftp 文件 我有这段代码 但我认为这不是处理重试的最佳方法 处理这个问题的最佳方法是什么 var exceptions new List
  • 在 Android AsyncTask 中获取 JSON

    我正在尝试获取 JSON 但我必须在 AsyncTask 中执行此操作 因为我在 logcat 中获取了它AndroidRuntime 18153 Caused by android os NetworkOnMainThreadExcept
  • Docker Compose 连接 ECONNREFUSED 172.18.0.4:3306

    当我使用以下命令构建项目的容器时 sudo docker build t PROJECT NAME 然后我通过这个 Docker Compose 配置下载 mysql 的镜像 db image mysql restart always po
  • 在 Windows Phone 8.1 上使用 MediaCapture 时拍摄的照片为黑色

    我正在使用 MediaCapture 捕获照片并存储它们 它可以在模拟器中运行 但当在真实手机 诺基亚 Lumia 530 上运行该应用程序时 捕获的照片只是黑色 它们具有正确的大小并且文件具有一定的字节长度 但是当显示照片时它是黑色的 请
  • 记忆游戏的 GUI 组件

    我正在做作业 所以我不要求代码 我想自己做这个 顺便说一句 我再次陷入 GUI 部分 并且代码部分没有什么问题 首先是按钮大小和图像大小 我没有使用按钮大小的方法 只是将图像设置为按钮的图标 但正如您在下面看到的 按钮不适合图像 第二件事是
  • 反序列化会导致列表条目的副本

    我想创建一个非常通用的模型层 它也可以作为 JSON 传递 一个模型应显示 RaspberryPi2 的 LED 面板 由于我希望对类进行尽可能接近现实的建模 因此我强制列表始终具有 8 8 个 LED 该类看起来像这样 public cl
  • 用子进程包装 cmd.exe

    我尝试使用以下程序在Windows下包装cmd exe 但它不起作用 它似乎在等待某些东西并且不显示任何内容 知道这里出了什么问题吗 import subprocess process subprocess Popen cmd exe sh
  • iphone sdk CGAffineTransform 获取物体的旋转角度

    我如何计算任何给定对象 即 uiimageview 的旋转角度 从技术上讲你不能 因为转换可以包括skew将图像变成平行四边形的操作 并且旋转角度不再定义 无论如何 由于旋转矩阵生成 cos x sin x 0 sin x cos x 0
  • VS2010 - 将 html 代码格式分配给 T4 (.tt) 文件

    我在 VS2010 中有一个 T4 文本模板 tt 主要用于生成 HTML 代码 基本上是一些包含和 JavaScript 是否可以指定 HTML 代码格式 颜色等 到该 tt 文件 情况 T4 想要有 更新Marcio Barcellos
  • MYSQL:如何查询JSON数组包含特定标签的位置

    MySQL 5 7 24 假设我有 3 行 如下所示 ID PK Name VARCHAR Data JSON 1 Admad label Color value Red label Age value 40 2 Saleem label
  • Struts 2重构代码以避免OGNL静态方法访问

    Struts 2 2 3 20 提到 将禁用对从表达式访问静态方法的支持 很快 请考虑重构您的应用程序 以避免进一步 问题 我们在验证器中使用了 OGNL 静态调用 ExpressionValidator expression foo ba
  • Spark SQL 中按日期分组的聚合

    我有一个包含时间戳的 RDDtime长类型 root id string nullable true value1 string nullable true value2 string nullable true time long nul
  • 如何使用命令行将新的 MySQL 数据库结构从开发网站迁移到生产网站?

    我有两个网站环境 独立的服务器 Media Temple DV 开发和生产 我们开始在生产上构建站点 然后获得了开发服务器 因此我最初使用如下命令将生产数据库移动到开发 mysqldump a u USERNAME p DATABASE g
  • 涉及多个变量的程序的时间复杂度

    最近 我被要求创建一个程序来查找文本片段中的最佳匹配 我已经成功编写了这个程序 但我确实对其时间复杂度有疑问 问题定义如下 给定一个查询 查找文档中出现的查询词并突出显示最佳标记 我的程序花费的时间 O m n p here m 文档长度
  • Facebook Connect + jQuery Mobile + Phonegap 构建

    我试图了解如何使用脸书连接 登录 与jQuery 移动 and 音隙构建 但随着我搜索这些信息的次数越多 我就越感到困惑 我已经在 Facebook 上创建了我的应用程序 并且我有 API 编号 我不知道最好的方法是否是调用 PHP 页面