Get facebook user profile using cordova

前端 未结 2 1630
时光取名叫无心
时光取名叫无心 2020-12-20 00:40

I want to get first name, last name, email when user login with facebook. My app is in Cordova. I am using cordova plugin for facebook authentication this one \"https://gith

2条回答
  •  误落风尘
    2020-12-20 01:14

    Try this Login Function with below Snippet.

    var fbLogin = function() {
        facebookConnectPlugin.login(["public_profile", "email", "user_birthday", "user_location"],
            function(response) {
                console.log("Login Response :" + JSON.stringify(response));
                //alert("Login Response :" + JSON.stringify(response))
                this.authId = response.authResponse.userID;
                if (response.status == "connected") {
                    facebookConnectPlugin.api("/" + response.authResponse.userID, ["public_profile", "email", "user_birthday", "user_location"],
                        function(result) {
                            this.email = result.email;
                            this.firstname = result.first_name;
                            this.lastname = result.last_name;
                            this.birthdate = result.birthday;
                            this.city = result.location.name;
                        },
                        function(error) {
                            alert("Failed: " + error);
                        });
                }
            },
            function(response) {
                alert("Other Response : " + JSON.stringify(response))
            });
    }
    

提交回复
热议问题