3 Replies Latest reply on Jun 25, 2017 10:58 AM by Gabit_Zhake

    Need example cordova-plugin-facebook4 for PhoneGap project

    Gabit_Zhake Level 1

      Hello !

       

      I added a in the file config.xml:

      <preference name="android-minSdkVersion" value="17"/>

      ...

      <preference name="phonegap-version" value="cli-6.5.0" />

      ...

      <plugin name="cordova-plugin-facebook4" spec="1.7.4" source="npm">

        <param name="APP_ID" value="XXXXXXXXXXXXXXX" />

        <param name="APP_NAME" value="MyProg" />

      </plugin>

       

       

      The application is already registered in facebook and it was indicated above instead of X...

       

      Please give an example of using the plugin - cordova-plugin-facebook4 for PhoneGap project.

      I did not find a suitable example from this resource - https://www.npmjs.com/package/cordova-plugin-facebook4

        • 1. Re: Need example cordova-plugin-facebook4 for PhoneGap project
          Gabit_Zhake Level 1

          I tried this:

          $(document).on("click", "#snid", function(){

                  facebookConnectPlugin.getLoginStatus(function(response) {

                      if (response.status === "connected") {

                          alert("Logged in, details:\n\n" + JSON.stringify(response.authResponse));

                      } else {

                          alert("Not logged in");

                      }

                  });

           

                  var fbLoginSuccess = function (userData) {

                      alert("UserInfo: ", userData);

                  };

           

                  facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,

                      function loginError (error) {

                          alert(error)

                      }

                  );

          });

           

           

          Show message: Not logged in

           

           

          Then it hangs:

          fb_1.png

          • 2. Re: Need example cordova-plugin-facebook4 for PhoneGap project
            Gabit_Zhake Level 1

            My code:

            try {

                 var fbLoginSuccess = function (userData) {

                      if (userData.status=='connected'){

                           facebookConnectPlugin.api("<user-id>/?fields=id,email", ["user_birthday"],

                                function onSuccess (result) {

                                     alert("Result: "+JSON.stringify(result));

                                }, function onError (error) {

                                     alert("Failed: "+JSON.stringify(error));

                                }

                           );

                      }

                 };

                 facebookConnectPlugin.login(["public_profile","email"], fbLoginSuccess,

                      function loginError (error) {

                           alert('error='+JSON.stringify(error))

                      }

                 );

            }

            catch (e) {

                 alert('error1='+e.message);

            }

             

            Result:

            fb_error1.png

             

            Did as a sample.

            Where is the mistake ?

            • 3. Re: Need example cordova-plugin-facebook4 for PhoneGap project
              Gabit_Zhake Level 1

              try {

                   var fbLoginSuccess = function (userData) {

                        if (userData.status=='connected'){

                             facebookConnectPlugin.api("me/?fields=id,last_name,first_name,birthday,email", [],

                                  function onSuccess (result) {

                                       alert("Result: "+JSON.stringify(result));

                                  }, function onError (error) {

                                       alert("Failed: "+JSON.stringify(error));

                                  }

                             );

                        }

                   };

                   facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,

                        function loginError (error) {

                             alert('error='+JSON.stringify(error))

                        }

                   );

              }

              catch (e) {

                   alert('error1='+e.message);

              }

               

              Result:

              fb_result_scr.png