大学のプロジェクトで Facebook API を作成する必要がありました。これらの値を Facebook から取得しようとしています。
現在のユーザー名と ID。友達の地理的位置、友達の ID と名前、共通の友達。
私は人生で Javascript SDK を見たことがないので、Web でいくつかの例を試してみました。
私はこれを得た:
//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と名前を保存する2つの配列が機能しているかどうかはわかりません。共通の友達と地理位置情報を取得する方法がわかりません
オンライン版はこちら: www.astrophilia.com.ar