Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为facebook graph sdk 1.0使用ionic facebook Connect插件?_Javascript_Facebook_Facebook Graph Api_Cordova_Ionic Framework - Fatal编程技术网

Javascript 如何为facebook graph sdk 1.0使用ionic facebook Connect插件?

Javascript 如何为facebook graph sdk 1.0使用ionic facebook Connect插件?,javascript,facebook,facebook-graph-api,cordova,ionic-framework,Javascript,Facebook,Facebook Graph Api,Cordova,Ionic Framework,我目前正在我的网站上使用facebooks javascript sdk,使用以下代码段: window.fbAsyncInit = function() { FB.init({ appId : 'appid', status : true, xfbml : true }); FB.Event.subscribe('auth.authResponseC

我目前正在我的网站上使用facebooks javascript sdk,使用以下代码段:

      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'appid',
          status     : true,
          xfbml      : true
        });

      FB.Event.subscribe('auth.authResponseChange', function(response) {
          if (response.status === 'connected') {
            console.log(response);
            console.log('Logged in');
          } else {
            FB.login();
          }
        });
      };

      (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "//connect.facebook.net/en_US/all.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
这很有效。但是,我正在将该应用程序转换为Ionic应用程序,因此我下载了
com.phonegap.plugins.facebookconnect
插件,并用以下内容替换了我的初始化脚本:

/*
 * @author Ally Ogilvie
 * @copyright Wizcorp Inc. [ Incorporated Wizards ] 2014
 * @file - facebookConnectPlugin.js
 * @about - JavaScript interface for PhoneGap bridge to Facebook Connect SDK
 *
 *
 */

if (!window.cordova) {
// This should override the existing facebookConnectPlugin object created from cordova_plugins.js
    var facebookConnectPlugin = {

        getLoginStatus: function (s, f) {
            // Try will catch errors when SDK has not been init
            try {
                FB.getLoginStatus(function (response) {
                    s(response);
                });
            } catch (error) {
                if (!f) {
                    console.error(error.message);
                } else {
                    f(error.message);
                }
            }
        },

        showDialog: function (options, s, f) {

            if (!options.name) {
                options.name = "";
            }
            if (!options.message) {
                options.message = "";
            }
            if (!options.caption) {
                options.caption = "";
            }
            if (!options.description) {
                options.description = "";
            }
            if (!options.link) {
                options.link = "";
            }
            if (!options.picture) {
                options.picture = "";
            }

            // Try will catch errors when SDK has not been init
            try {
                FB.ui({
                    method: options.method,
                    message: options.message,
                    name: options.name,
                    caption: options.caption,
                    description: (
                        options.description
                    ),
                    link: options.link,
                    picture: options.picture
                },
                function (response) {
                    if (response && response.request) {
                        s(response);
                    } else {
                        f(response);
                    }
                });
            } catch (error) {
                if (!f) {
                    console.error(error.message);
                } else {
                    f(error.message);
                }
            }
        },
        // Attach this to a UI element, this requires user interaction.
        login: function (permissions, s, f) {
            // JS SDK takes an object here but the native SDKs use array.
            var permissionObj = {};
            if (permissions && permissions.length > 0) {
                permissionObj.scope = permissions.toString();
            }

            FB.login(function (response) {
                if (response.authResponse) {
                    s(response);
                } else {
                    f(response.status);
                }
            }, permissionObj);
        },

        getAccessToken: function (s, f) {
            var response = FB.getAccessToken();
            if (!response) {
                if (!f) {
                    console.error("NO_TOKEN");
                } else {
                    f("NO_TOKEN");
                }
            } else {
                s(response);
            }
        },

        logEvent: function (eventName, params, valueToSum, s, f) {
            // AppEvents are not avaliable in JS.
            s();
        },

        logPurchase: function (value, currency, s, f) {
            // AppEvents are not avaliable in JS.
            s();
        },

        logout: function (s, f) {
            // Try will catch errors when SDK has not been init
            try {
                FB.logout( function (response) {
                    s(response);
                })
            } catch (error) {
                if (!f) {
                    console.error(error.message);
                } else {
                    f(error.message);
                }
            }
        },

        api: function (graphPath, permissions, s, f) {
            // JS API does not take additional permissions

            // Try will catch errors when SDK has not been init
            try {
                FB.api(graphPath, function (response) {
                    if (response.error) {
                        f(response);
                    } else {
                        s(response);
                    }
                });
            } catch (error) {
                if (!f) {
                    console.error(error.message);
                } else {
                    f(error.message);
                }
            }
        },

        // Browser wrapper API ONLY
        browserInit: function (appId, version) {
            if (!version) {
                version = "v2.0";
            }
            FB.init({
                appId      : appId,
                cookie     : true,
                xfbml      : true,
                version    : version
            })
        }
    };

    // Bake in the JS SDK
    (function () {
        if (!window.FB) {
            console.log("launching FB SDK")
            var e = document.createElement('script');
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }
    }());

}
然而,当我添加这个时,它将我提升到facebook sdk的v2.0

我甚至用它替换了facebookConnectPlugin.js代码的一部分,以强制使用api v1.0

    // Browser wrapper API ONLY
    browserInit: function (appId, version) {
        if (!version) {
            version = "v1.0";
        }
        FB.init({
            appId      : appId,
            cookie     : true,
            xfbml      : true,
            version    : version
        })
    }

然而,这仍然给了我2.0版

如果你的应用程序在2014年4月30日之前创建并激活,你只能使用API v1.0。如果不是,你就不能使用API v1.0。是的,我已经成功地使用了API v1.0。我所要做的就是使用ionic框架将网站包装成一个移动应用程序。我想我需要使用该插件,因为否则它将无法启动facebook应用程序进行登录-因此我甚至无法在不使用该插件的情况下登录。那么传递到该函数中的版本是什么呢?当我在该函数中
console.log(version)
时,会返回
v1.0
。当我取消注释它时,它仍然引导我进入v2.0。你的应用程序id是什么?