Ionic cordova-facebook-plugin4无法通过api图形调用

时间:2017-03-28 10:36:24

标签: ios cordova facebook-graph-api ionic2

我有一个我正在构建的应用程序,我在Android设备上运行的代码非常好,但在iOS上给我一个图形api错误。

以下是我用于登录facebook的代码。

   constructor(private menuCtrl: MenuController, private nav: NavController, private playerService: Players, private userService: Users, private packService: Packs, private modalCtrl: ModalController, private loadingCtrl: LoadingController) {
        Facebook.browserInit(this.FB_APP_ID, "v2.8");
        menuCtrl.enable(false, 'navMenu');
    }

    ionViewLoaded() {
    }

    doFbLogin() {
        var permissions = new Array();
        let nav = this.nav;
        let userService = this.userService;
        let playerService = this.playerService;
        let packService = this.packService;
        var menuCtrl = this.menuCtrl;
        //the permissions your facebook app needs from the user
        permissions = ["public_profile", "email", "user_friends"];


        Facebook.login(permissions)
            .then(function (response) {
                let userId = response.authResponse.userID;
                //Getting name and gender properties
                Facebook.api("me/?fields=name,gender,email,friends", permissions)
                    .then(function (user) {
                        user.picture = "https://graph.facebook.com/" + userId + "/picture?type=large";
                        user.fbid = user.id;
                        //now we have the users info, let's save it in the NativeStorage
                        NativeStorage.setItem('user',
                            {
                                userid: userId,
                                name: user.name,
                                gender: user.gender,
                                picture: user.picture,
                                email: user.email,
                                fbid: user.id
                            })
                            .then(function (user) {
                                console.log("email to check", user.email);
                                //now we check if there is an existing account with this email address.
                                userService.accountExists(user.email).then((data) => {
                                    let founduser = data;
                                    if (founduser) {
                                        user = founduser;
                                        console.log("existing user no account created");
                                        menuCtrl.enable(true, 'navMenu');
                                        nav.setRoot(Dashboard);
                                        nav.pop();
                                        nav.push(Dashboard);
                                    } else {
                                        user.wins = 0;
                                        user.draws = 0;
                                        user.losses = 0;
                                        user.authenticated = true;
                                        user.maroon_points = 0;
                                        userService.createUser(user);
                                        var createdUser = {};

                                        //get user id of newly created user from db
                                        userService.accountExists(user.email).then((data) => {
                                            createdUser = { '_id': data._id };
                                            if (createdUser) {
                                                playerService.getStarterPlayers().then((data) => {
                                                    var starters = data;
                                                    let i = 0;
                                                    while (i < _.keys(starters).length) {
                                                        let playerObj = {
                                                            userid: createdUser['_id'],
                                                            playerid: starters[i]._id,
                                                            position: starters[i].position
                                                        };
                                                        console.log("playerObj[" + i + "]", playerObj);
                                                        playerService.giveOwnedPlayer(playerObj);
                                                        i++
                                                    }
                                                });

                                                packService.getStarter().then((data) => {
                                                    var packsChosen = data;
                                                    let j = 0;
                                                    while (j < _.keys(packsChosen).length) {
                                                        let packObj = {
                                                            _id: packsChosen[j]._id,
                                                            owner: createdUser['_id']
                                                        };
                                                        console.log("packObj[" + j + "]", packObj);
                                                        packService.giveSingle(packObj);
                                                        j++
                                                    }
                                                });

                                                menuCtrl.enable(true, 'navMenu');
                                                nav.setRoot(Dashboard);
                                                nav.pop();
                                                nav.push(Dashboard);
                                            } else {
                                                console.error("NO USER FOUND");
                                            }
                                        });
                                        console.log("no existing user account created!");
                                    }
                                });
                            }, function (error) {
                                console.log(error);
                            })
                    })
            }, function (error) {
                console.log("error - FB graph call failed", error);
            });
    }

以下是在iOS 10 iphone 6上检查应用程序时在safari Web控制台中引发的错误。

[Error] EXCEPTION: Uncaught (in promise): There was an error making the graph call.
    handleError (main.js:81941)
    handleError (main.js:152942)
    next (main.js:55809:94)
    (anonymous function) (main.js:57865)
    __tryOrUnsub (main.js:1389)
    next (main.js:1338)
    _next (main.js:1291)
    next (main.js:1255)
    next (main.js:7764)
    emit (main.js:57851)
    triggerError (main.js:41831)
    onHandleError (main.js:41792)
    runGuarded (polyfills.js:3:7279)
    r (polyfills.js:3:3818)
    i (polyfills.js:3:3867)
    invoke (polyfills.js:3:11439)
    (anonymous function) (polyfills.js:2:30199)

[Error] ORIGINAL STACKTRACE:
    handleError (main.js:81946)
    handleError (main.js:152942)
    next (main.js:55809:94)
    (anonymous function) (main.js:57865)
    __tryOrUnsub (main.js:1389)
    next (main.js:1338)
    _next (main.js:1291)
    next (main.js:1255)
    next (main.js:7764)
    emit (main.js:57851)
    triggerError (main.js:41831)
    onHandleError (main.js:41792)
    runGuarded (polyfills.js:3:7279)
    r (polyfills.js:3:3818)
    i (polyfills.js:3:3867)
    invoke (polyfills.js:3:11439)
    (anonymous function) (polyfills.js:2:30199)

[Error] v@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:4869
s@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:4298
s@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:4113
file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:4653
invokeTask@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:10289
onInvokeTask@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/main.js:41762:47
invokeTask@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:10232
runTask@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:7647
i@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:3714
invoke@file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:3:11438
file:///var/containers/Bundle/Application/704E4F8E-C28D-49C9-9393-0CDA54106CAF/Pitchlife.app/www/build/polyfills.js:2:30198
    handleError (main.js:81947)
    handleError (main.js:152942)
    next (main.js:55809:94)
    (anonymous function) (main.js:57865)
    __tryOrUnsub (main.js:1389)
    next (main.js:1338)
    _next (main.js:1291)
    next (main.js:1255)
    next (main.js:7764)
    emit (main.js:57851)
    triggerError (main.js:41831)
    onHandleError (main.js:41792)
    runGuarded (polyfills.js:3:7279)
    r (polyfills.js:3:3818)
    i (polyfills.js:3:3867)
    invoke (polyfills.js:3:11439)
    (anonymous function) (polyfills.js:2:30199)

1 个答案:

答案 0 :(得分:0)

问题是在xcode中编译代码的其他用户有我使用的大多数全局插件的过时版本,包括cordova。更新这些,删除和添加ios平台,然后从github master添加cordova-facebook-plugin4并进行重建似乎解决了这个问题。