Dinesh
Dinesh

Reputation: 175

How to integrate twitter, facebook social sharing api in Phonegap 2.7.0

I am trying to integrate twitter social sharing api to share links from my phone gap application.

as i have read from the blog given here

http://oodlestechnologies.com/blogs/Twitter-integration-on-PhoneGap-using-ChildBrowser-and-OAuth-for-iOS-and-Android-Platforms

Its is asking to install ChildBrowser plugin first.

I have downloaded the plugin from github as

https://github.com/alunny/ChildBrowser

And as i have tried to install it in my project the java file is giving too much errors.

As i have tried to resolve errors with suggestion given in eclipse. And when i run the project as android application it is saying exec() unknown plugin ChildBrowser

I am adding the plugin in config.xml as

<plugin name="ChildBrowser" value="android.com.phonegap.plugins.childBrowser.ChildBrowser"/> 

I Just want to clear that the child browser plugin works with PhoneGap 2.7.0 Or not . If not then how can i use twitter sharing for my app.

If i am wrong anywhere please correct me. And also is there any best way to implement social sharing in phonegap application

Thanks

Upvotes: 0

Views: 4797

Answers (2)

Eddy Verbruggen
Eddy Verbruggen

Reputation: 3550

for PhoneGap social sharing, there is a much easier way. Just use the plugin mentioned here and you'll be able to share images via the native sharing widget, or directly to Twitter or Facebook.

The native sharing widget on iOS 7

Upvotes: 6

Ved
Ved

Reputation: 2701

Use simple InAppBrowser

Twitter Sharing url

var tweeter_url = 'https://twitter.com/intent/tweet?source=webclient&text='+your_text_or_share_url;

var ref = window.open(tweeter_url, 'random_string', 'location=no');
ref.addEventListener('loadstart', function(event) {
                   console.log(event.type + ' - ' + event.url);
} );
ref.addEventListener('loadstop', function(event) {
     console.log(event.type + ' - ' + event.url);

     if(event.url == 'https://mobile.twitter.com/'){

         setTimeout(function() {
                    ref.close();
         }, 1000);
     }

} );
ref.addEventListener('exit', function(event) {
                  //console.log(event.type + ' - ' + event.url);
} );

Facebook Sharing url

var facebook_url = "https://www.facebook.com/dialog/feed?app_id=your_app_id&link="+encodeURIComponent(urlPost)+"&picture="+encodeURIComponent(urlPicture)+"&name="+encodeURIComponent(Title)+"&caption=&description="+encodeURIComponent(message)+"&redirect_uri="+your_redirect_uri;
var ref = window.open(url, 'random_string', 'location=no');

ref.addEventListener('loadstart', function(event) {

});
ref.addEventListener('loadstop', function(event) {
     console.log(event.type + ' - ' + event.url);
     var post_id = event.url.split("post_id=")[1];
     var cancel_url = event.url.split("#")[0];
     if(post_id != undefined){
            setTimeout(function() {
                ref.close();                    
            }, 5000);
     }
     if(cancel_url != undefined && cancel_url == your_redirect_uri){
            setTimeout(function() {
                ref.close();                        
            }, 1000);
     }                         
});
ref.addEventListener('exit', function(event) {

}); 

Upvotes: 1

Related Questions