5

Phonegap 2.7.0 有 Facebook 插件吗?

当我们尝试以下方法时,我们最终会在 Phonegap 2.7.0 上遇到已弃用的错误。

https://github.com/phonegap/phonegap-facebook-plugin/blob/master/README.md

当我们谷歌它时,我们找不到任何东西。

谢谢,

席德

4

1 回答 1

3

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

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 上找到文档

于 2013-05-16T05:29:18.587 回答