1

OK, so this is driving me nuts. Have been trying to get the access token for my app using jquery. When I have the access token everyting is working fine. I can retrieve friends list etc. If I sniff the URL from my request and paste it in a browser it does as expected (gives me the access token and redirects to my page).

But...using the below function either results in a "jQuery15105307047630302168_1315247312743 was not called" or if I change the dataType to "JSON" in a "No transport" error message. I have been reading a bunch of posts and nothing seems to do the trick.

Some suggest adding ?callback? and a parameter which is the callback function itself, but this gives me the exact same error. Below is the function that I am calling to get the access token.

function GetAccessTokenClient() {

var redirURL = "http://banana.ihedge.dk/bet/";
var scope = "user_online_presence"; // user_photos, email, user_birthday, user_online_presence
var clientID = "105719222863801";

try {
    $.ajax({
        type: "GET",
        url: "https://www.facebook.com/dialog/oauth", //"https://graph.facebook.com/oauth/authorize",
        cache: false,,
        dataType: 'JSONP',
        data: "client_id=" + clientID + "&redirect_uri=" + redirURL + "&reponse_type=token",
        error: function(xhr, status, error) {
            alert(error);
        },
        success: function(response) {
            for (key in repsonse)
                alert(key);
        },
        complete: function(request, textStatus) {
            //alert('RESPONSETEXT: ' + request.responseText);
            //alert('COMPLETE: ' + textStatus);
        }
    });
}
catch (Error) {
    alert(Error);
}
}

Please help.

4

1 回答 1

2

问题在于尝试使用 ajax获取https://www.facebook.com/dialog/oauth ,它不是为我设计的。

使用 javascript/jquery 获取用户访问令牌的最简单方法是使用 FB.Login

FB.login(function(response) {
    if (response.authResponse) {
        var accessToken = response.authResponse.accessToken;
    }
});
于 2011-09-05T19:17:07.947 回答