Facebook sharing using FB Messenger app from your phonegap application

Posted By : Deepak Rawat | 29-Jun-2015

Hi guys,

 

We can share to facebook using share dialogue and message dialogue, in my earlier blog I told you about using share dialogue for sharing data from your phonegap application. Share dialogue shares data using FB native app as well as feed dialogue(in case native FB app is not installed), while sharing through FB messenger app the user must have native FB messenger app for sharing.

 

When using message dialogue the your app switches to FB native messenger app and when the post is shared or user cancel the post, then the user will be redirected to your app, once this post is shared it will be shown to the personal message of the messenger app.

 

Requirement for using messenger app for sharing on FB:

  • Register your app on facebook and get the App_Id.

  • Clone the plugin from https://github.com/Wizcorp/phonegap-facebook-plugin/

  • Install plugin locally using cordova plugin add ../phonegap-facebook-plugin-master --variable APP_ID="Your_App_Id" --variable APP_NAME="Your_App_Name"


After the plugin is installed you need to write the code same like when we share using share dialogue, and use the showDialog() method of the plugin to redirect the user to messenger app:

 

 var fbData = {
        
        method : "send",
        
        link : 'https://www.mynewapp.com',
        
        href : 'https://www.mynewapp.com',
        
        description : "Checkout my new app",
        
        name : "My App",
        
        caption : "www.mynewapp.com",
        
        picture : "https://s3.amazonaws.com/oodles-blogs/blog-images/7a5d578c-12b8-4223-bab7-7921f3ad9843.png"
    };
    
    facebookConnectPlugin.showDialog(fbData, function(dialogSuccess) {
          console.log("Share success " + JSON.stringify(dialogSuccess));               
    }, function(dialogFaliure) {
          console.log("Share Faliure " + JSON.stringify(dialogFaliure));
    });
 

 

Same as share dialogue the fbData will all the attributes, the only difference here is the name of the method i.e. “send” , your post will be shown same as it is shown when we share using share dialogue. The difference here is that the post will not be shown on the receiver’s new feed but it is shown as a personal message.


Note: This sharing functionality uses the native FB messenger app to share. If you want to check the details regarding share dialogue refer to my previous blog here.

 

 

About Author

Author Image
Deepak Rawat

Deepak is a Web and Mobile application Sr. Lead Frontend developer and good working experience with JQuery , AngularJS , Javascript and PhoneGap. His hobbies are listening to music and photography.

Request for Proposal

Name is required

Comment is required

Sending message..