是否有适用于 phonegap 2.7.0 的 Facebook 插件? [英] Is there any Facebook plugin for phonegap 2.7.0?

查看:18
本文介绍了是否有适用于 phonegap 2.7.0 的 Facebook 插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有适用于 Phonegap 2.7.0 的 Facebook 插件?

Is there any Facebook plugin for Phonegap 2.7.0?

当我们尝试下面的方法时,我们最终在 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

我们在 Google 上找不到任何东西.

We couldn't find anything when we Google it.

谢谢,

席德

推荐答案

我建议您使用 phonegap 附带的 inappbrowser 插件来执行此操作.. 示例如下所示.在下面的xxx中填写您的相关信息

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");
                }
            }); 
        }
    }

我会添加更多用于注销和发布到墙上等的功能.您可以在 inappbrowser 上找到文档这里

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆