phonegap 无法与 facebook 整合

Posted

技术标签:

【中文标题】phonegap 无法与 facebook 整合【英文标题】:phonegap unable to integrate with facebook 【发布时间】:2013-11-22 09:37:22 【问题描述】:

我正在尝试在专门用于 Windows Phone 平台的 Phonegap 应用程序上执行 Facebook 登录。

我已经下载了所需的插件(文件:ChildBrowserCommand.cs、ChildBrowser.js)和 FBConnect.js,地址为 https://github.com/purplecabbage/phonegap-plugins/tree/master/WindowsPhone。我还将 ChildBrowser.cs 文件包含到我的项目中

下面是我的简单 html 文件。一段时间后,我想执行 Facebook 登录:

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <link rel="stylesheet" href="css/jquery.mobile-1.3.2.min.css" />
    <script type="text/javascript" charset="utf-8" src="js/jquery/jquery.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery/jquery.mobile-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/run/cordova.js"></script>
    <script type="text/javascript" src="js/utils/ChildBrowser.js"></script>
    <script type="text/javascript" src="js/utils/FBConnect.js"></script>
    <title></title>
</head>
<body>
    <script>
        $.support.cors = true;
    </script>
    <div id="testPage" data-role="page">
         <script>
             setTimeout(function () 
                 var client_id = "...";
                 var redir_url = "http://www.facebook.com/connect/login_success.html";
                 var friendsMap = ;

                 var fb = FBConnect.install(client_id, redir_url, "touch");
                 fb.connect('email, read_stream, read_friendlists');
                 fb.onConnect = onFBConnected;
             , 2500);

             function onFBConnected() 
             
            </script>
        <div data-role="content">
        </div>
    </div>
</body>
</html>

但是当我编译我的项目时,我得到了以下错误:

1. The type or namespace name 'BaseCommand' could not be found
2. The type or namespace name 'JSON' does not exist in the namespace 'WP7CordovaClassLib.Cordova'

关于第一个错误,我看到 ChildBrowserCommand.cs 文件中有不正确的命名空间。我已经解决了这个问题,但我不知道在哪里可以找到丢失的 JSON 模块。从存档下载Phonegap 2.9.1 后,可以创建Visual Studio 模板(解压后在lib/windows-phone 目录下,我已经完成了),但似乎库可能不完整。仍然存在一个错误,我无法执行 Facebook 登录。你有没有遇到过这个问题?在哪里可以找到这个缺失的模块?下面是我的 ChildBrowserCommand.cs 更改。我将不胜感激!

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Diagnostics;
using System.Runtime.Serialization;
using WP7CordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands; // previous: using WP7CordovaClassLib.Cordova.Commands;
using WP7CordovaClassLib.Cordova.JSON; // it's missing
using Microsoft.Phone.Shell;

【问题讨论】:

【参考方案1】:

更新: 前段时间我发现了非常好的解决方案HERE。它适用于我的 Windows Phone 应用程序!为了正确执行 Facebook 登录,您需要在 Phonegap 项目中设置 InAppBrowser 插件,并在 .FaceGap 方法调用之前输入您的 App ID 和 App Secret 密钥。杰出的! :)

【讨论】:

以上是关于phonegap 无法与 facebook 整合的主要内容,如果未能解决你的问题,请参考以下文章

Facebook Phonegap 插件 - 能够登录(似乎)但无法获取访问令牌

Facebook“错误 2”与 Phonegap 在 ios 上构建 Facebook Connect 插件

Facebook 插件不适用于 phonegap 构建

Phonegap + Facebook 插件:为 iOs 准备的 Xcodeproj 包

使用Phonegap Facebook Connect Plugin API的离子框架无法使朋友分页工作

Phonegap 构建 facebook 连接插件 (android)