0

我必须为一个大学项目做一个 facebook API。我正在尝试从 Facebook 获取这些值。

当前用户名和 id。朋友的地理位置、朋友的 ID 和姓名、共同的朋友。

我一生中从未见过 Javascript SDK,所以我尝试研究网络中的一些示例。

我懂了:

    //facebook app id
var mis_amigos_id = new Array();
var mis_amigos_name = new Array();
appid='512456102098788';
channelurl='www.astrophilia.com.ar/facebook-load-friends/includes/channel.html';

//function to get current userid
function getUser()
{
    FB.init({
        appId      : '512456102098788', // App ID
        channelUrl : 'www.astrophilia.com.ar/facebook-load-friends/includes/channel.html', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
    });
    //check current user login status
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            loadFriends();
        } else {
            //user is not connected.
            FB.login(function(response) {
                if (response.authResponse) {
                    loadFriends();
                } else {
                    alert('User cancelled login or did not fully authorize.');
                }
            });
        }
    });
}

//funcion que carga amigos, this function load the friends
function loadFriends()
{
    //i think this is a json objet with all the data
    FB.api('/me/friends', function(response) {
        console.log(response);
        var divContainer=$('.facebook-friends');
        //this for sees all friends
        for(i=0;i<response.data.length;i++)
            {
                mis_amigos_id[i] = response.data[i].id;
                mis_amigos_name[i] = response.data[i].name;
                document.write(mis_amigos_name[i]+" tiene el id "+mis_amigos_id[i]+"</ br>");

                // original code: creates a img element: response.data.id is the id of the current friend
                                                                                                                                                                                 //$(document.createElement("img")).attr({ src: 'https://graph.facebook.com/'+response.data[i].id+'/picture', title: response.data[i].name ,onClick:'alert("You poked "+this.title);'})
                                                                                                                                                                                 //apend to div container. osea que imprime la imagen en el div.
               // .appendTo(divContainer);       
            }
    });
}

//start from here
$(document).ready(function(){
    $('.load-button').click(function(){
        getUser();
    });
});

document.write 有问题。而且我不确定保存 id 和 name 的两个数组是否正常工作。我不知道如何获得共同的朋友和地理位置

这是在线版本:www.astrophilia.com.ar

4

0 回答 0