有没有用于phonegap 2.7.0的Facebook插件? [英] Is there any Facebook plugin for phonegap 2.7.0?
问题描述
Phonegap 2.7.0是否有任何Facebook插件?
当我们尝试下面的一个时,我们最终会在Phonegap 2.7.0上出现弃用的错误。 / p>
https:// github。 com / phonegap / phonegap-facebook-plugin / blob / master / README.md
我们在Google上找不到任何东西。
谢谢,
Sid
我建议你使用inappbrowser插件自带phonegap做这个..示例如下所示。
在下面的xxx中填入您的相关信息
var my_client_id =xxxxxx,//您的应用程序ID
my_secret =xxxxxxxxx,//您的应用程式秘密
my_redirect_uri =https://www.facebook.com/connect/login_success.html,// LEAVE THIS
my_type =user_agent ,my_display =touch; // LEAVE THIS
var facebook_token =fbToken; // OUR TOKEN KEEPER
var ref; // IN APP BROWSER REFERENCE
// FACEBOOK
var Facebook = {
init:function(){
//开始授权
var authorize_url = https://www.facebook.com/dialog/oauth?;
authorize_url + =client_id =+ my_client_id;
authorize_url + =& redirect_uri =+ my_redirect_uri;
authorize_url + =& display =+ my_display;
authorize_url + =& scope = publish_stream;
//使用链接调用应用程序浏览器
ref = window.open(authorize_url,'_blank','location = no');
ref.addEventListener('loadstart',function(event){
Facebook.facebookLocChanged(event.url);
});
},
facebookLocChanged:function(loc){
if(loc.indexOf(code =)> = 1){
//关闭INAPPBROWSER并导航到INDEX
ref.close();
//这是要在服务器端保护客户端秘密
var codeUrl ='https://graph.facebook.com/oauth/access_token?client_id='+my_client_id+ '& client_secret ='+ my_secret +'& redirect_uri ='+ my_redirect_uri +'& code ='+ loc.split(=)[1];
console.log('CODE_URL ::'+ codeUrl);
$ .ajax({
url:codeUrl,
data:{},
type:'POST',
async:false,
cache: false,
success:function(data,status){
//我们在这里存储
localStorage.setItem(facebook_token,data.split('=')[1] .split '&')[0]);
},
错误:function(){
alert(Unknown error Occured);
}
} ;
}
}
我会添加更多功能注销和发布到墙等
您可以在inappbrowser上找到文档此处
Is there any Facebook plugin for Phonegap 2.7.0?
When we try the below one, we are end up with deprecated error on Phonegap 2.7.0.
https://github.com/phonegap/phonegap-facebook-plugin/blob/master/README.md
We couldn't find anything when we Google it.
Thank you,
Sid
I would suggest you use the inappbrowser plugin that comes with phonegap to do this .. example shown below. Fill in the xxx below with your relevant info
var my_client_id = "xxxxxx", // YOUR APP ID
my_secret = "xxxxxxxxx", // YOUR APP SECRET
my_redirect_uri = "https://www.facebook.com/connect/login_success.html", // LEAVE THIS
my_type ="user_agent", my_display = "touch"; // LEAVE THIS
var facebook_token = "fbToken"; // OUR TOKEN KEEPER
var ref; //IN APP BROWSER REFERENCE
// FACEBOOK
var Facebook = {
init:function(){
// Begin Authorization
var authorize_url = "https://www.facebook.com/dialog/oauth?";
authorize_url += "client_id=" + my_client_id;
authorize_url += "&redirect_uri=" + my_redirect_uri;
authorize_url += "&display=" + my_display;
authorize_url += "&scope=publish_stream";
//CALL IN APP BROWSER WITH THE LINK
ref = window.open(authorize_url, '_blank', 'location=no');
ref.addEventListener('loadstart', function(event){
Facebook.facebookLocChanged(event.url);
});
},
facebookLocChanged:function(loc){
if (loc.indexOf("code=") >= 1 ) {
//CLOSE INAPPBROWSER AND NAVIGATE TO INDEX
ref.close();
//THIS IS MEANT TO BE DONE ON SERVER SIDE TO PROTECT CLIENT SECRET
var codeUrl = 'https://graph.facebook.com/oauth/access_token?client_id='+my_client_id+'&client_secret='+my_secret+'&redirect_uri='+my_redirect_uri+'&code='+loc.split("=")[1];
console.log('CODE_URL::' + codeUrl);
$.ajax({
url: codeUrl,
data: {},
type: 'POST',
async: false,
cache: false,
success: function(data, status){
//WE STORE THE TOKEN HERE
localStorage.setItem(facebook_token, data.split('=')[1].split('&')[0]);
},
error: function(){
alert("Unknown error Occured");
}
});
}
}
I would add more functions for logout and posting to a wall etc. You can find documenatation on the inappbrowser here
这篇关于有没有用于phonegap 2.7.0的Facebook插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!