繁体   English   中英

新的Facebook API问题

[英]New Facebook API issue

谁能帮我这个代码,告诉我哪里出了问题?

我的代码无法再使用新的Facebook API,并且出现以下错误!

Uncaught Error: OAuth2 specification states that 'perms' should now be called 
'scope'. Please update.

Error is in http://connect.facebook.net/en_US/all.js line 23

即使我更改了它,它仍然根本不起作用!

//THIS FUNCTION WILL INITIALIZE THE FACEBOOK API AND WILL ADD NEW FACEBOOK ACCOUNTS.
var apikey = $("#apikey").val();
//var tuittingID = $("#tuittingID").val();
FB.init({ apiKey: apikey, status : true, cookie : true, oauth: true });
FB.getLoginStatus(handleSessionResponse);
$('#FBlogin').live('click', function() {
    FB.login(handleSessionResponse, {
        scope:'manage_pages, publish_stream, offline_access, user_status, 
        read_insights'
    });
    return false;
});
function handleSessionResponse(response) {
    if (!response.session || String(response.scope) == '') {
        return;
    }
    else
    var tuittingID = $.cookie("tuittingID");
    $('#AccessToken').val(response.session.access_token);
    $("#loader").show();
    $.post("tuitting/facebook_lib/fbadd.php",
    { tuittingID: tuittingID, uid: FB.getSession().uid, usid: 
    FB.getSession().session_key, accesstoken: response.session.access_token },
    function(data){
        reloadAccounts();
        $("#loader").hide();
        FB.logout(function(response) {
        }); //END LOGOUT FROM FACEBOOK AFTER SUCCESSFULL ACTION
    }
    ); //END AJAX POST FUNCTION DATA
}

您是否进行了支持Oauth 2所需的更改? 自10月1日起强制执行此操作,但SDK仅在昨天(2012年12月13日)被强制使用Oauth 2

请参阅https://developers.facebook.com/docs/oauth2-https-migration/-有关更改内容的摘要以及指向即将发布的博客文章的链接-身份验证和javascript文档是您最可能需要的文档检查您是否要进行更改,因为这是更改的地方

我们也受到此更改的影响,我们进行了以下更改以使其起作用。 FB.init()是按以下代码要求的,并且oauth设置为true。

        FB.init({
        appId: 1234567890123,
        oauth: true
    })

现在不再有会话, response.session变为response.authResponseresponse.session.uid变为response.authResponse.userID

            FB.login(function(response) {
        if (response.authResponse) {
                var postData = {
                    FBID: response.authResponse.userID,
                    Access_Token: response.authResponse.accessToken
                };

链接有关js更改的其他信息,要求https://developers.facebook.com/blog/post/525/

还要确保您使用的是FB.getAuthResponse()而不是FB.getSession()。

http://developers.facebook.com/docs/reference/javascript/FB.getAuthResponse/ http://developers.facebook.com/blog/post/525/

这是Oauth 1.0代码:

html

<div id="fb-root"></div>
<div class="fb-login-button" scope="email,user_birthday" 
onlogin="afterFacebookConnect();" autologoutlink="false">Login con Facebook</div>

javascript

        window.fbAsyncInit = function () {
            FB.init({
                appId: 'id_of_app',
                status: true,
                cookie: true,
                xfbml: true                });
        };


        if (document.getElementById('fb-root') != undefined) {
            var e = document.createElement('script');
            e.type = 'text/javascript';
            e.src = document.location.protocol + '//connect.facebook.net/es_ES/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }


function afterFacebookConnect() {
    FB.getLoginStatus(function (response) {
        if (response.session) {
            window.location = "/facebook/login?token=" + response.session.accessToken;
        } else {
            // user clicked Cancel
        }
    });
}

我为适应Oauth 2.0所做的更改:

   window.fbAsyncInit = function () {
        FB.init({
            appId: 'id_of_app',
            status: true,
            cookie: true,
            xfbml: true,
            oauth:true // additional parameter
        });
    };

function afterFacebookConnect() {
    FB.getLoginStatus(function (response) {
        if (response.authResponse) {
            window.location = "/facebook/login?token=" 
           + response.authResponse.accessToken;
        } else {
            // user clicked Cancel
        }
    });
}

附加:这是处理响应的代码(ASP.NET MVC,C#):

使用Newtonsoft.Json.Linq;

   [RequireHttps]
    public ActionResult login(string token)
    {
        WebClient client = new WebClient();

            string JsonResult = client.DownloadString(string.Concat(
                   "https://graph.facebook.com/me?access_token=", token));
            JObject jsonUserInfo = JObject.Parse(JsonResult);

            string nombre = jsonUserInfo.Value<string>("first_name");
            string segundo_apellido = jsonUserInfo.Value<string>("last_name");
            string nombre_completo = jsonUserInfo.Value<string>("name");
            string genero = jsonUserInfo.Value<string>("gender");
            string email = jsonUserInfo.Value<string>("email");
            string birthday = jsonUserInfo.Value<string>("birthday");

    // here you do your logic to login the user 
    // otherwise you can send user to the registration 
    // form and fill in some data you received from facebook

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM