通过 PhoneGap 在 Facebook 上共享数据
使用子浏览器或 InAppbrowser 插件,然后添加以下代码
function FBConnect()
{
if(window.plugins.childBrowser == null)
{
ChildBrowser.install();
}
}
$("#share_on_wall").live("click", function(event){
if(event.handled !== true){
var fb = FBConnect.install();
fb.postFBWall(desc, post_url, vPromotionPicture_url, vTitle);
event.handled = true;
}
return false;
});
FBConnect.prototype.postFBWall = function(message, urlPost, urlPicture, vTitle)
{
if(urlPicture == undefined)
urlPicture = "";
urlPost ="";
var url = "https://www.facebook.com/dialog/feed?app_id=your_app_id&link="+encodeURIComponent(urlPost)+"&picture="+encodeURIComponent(urlPicture)+"&name="+encodeURIComponent(vTitle)+"&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) {
});
}