如何在Phonegap 2.7.0中集成twitter,facebook社交分享API

时间:2013-12-24 13:07:40

标签: android facebook twitter cordova

我正在尝试整合Twitter社交分享API来分享我手机差距应用程序中的链接。

正如我从这里给出的博客中读到的那样

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

它要求首先安装ChildBrowser插件。

我已经从github下载了插件

https://github.com/alunny/ChildBrowser

因为我试图在我的项目中安装它,java文件会产生太多错误。

因为我试图用eclipse中给出的建议来解决错误。当我将项目作为android应用程序运行时,它会说exec()未知的插件ChildBrowser

我在config.xml中添加了插件

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

我只是想澄清一下,儿童浏览器插件是否适用于PhoneGap 2.7.0。如果没有,那么我如何使用Twitter共享我的应用程序。

如果我错了,请纠正我。还有在phonegap应用程序中实现社交共享的最佳方法

谢谢

2 个答案:

答案 0 :(得分:6)

对于PhoneGap社交分享,有一种更简单的方法。只需use the plugin mentioned here,您就可以通过本机共享小部件或直接与Twitter或Facebook共享图像。

The native sharing widget on iOS 7

答案 1 :(得分:1)

使用简单的InAppBrowser

Twitter分享网址

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分享网址

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) {

});