您实际上可以从公共 Facebook 窃取信息。它不漂亮,需要几秒钟,但有效。
我有一个从控制台运行并发出 AJAX 请求的 JS 代码 - 当您向下滚动时(http://www.facebook.com/profile.php?sk=friends)在常规 facebook UI 中请求更多朋友时,同样的 facebooks . 然后我解析结果。到目前为止,它完美无缺。我只是要求更多的朋友,当我没有得到匹配时,我知道我拥有他们所有人。
我不想分享整个代码,但这是必不可少的部分:
// Recursively load person friends
function getMoreFriends(job, uid, fb_dtsg, post_form_id, offset, callback, finished ){
var url = "http://www.facebook.com/ajax/browser/list/friends/all/?uid="+uid+"&offset="+offset+"&dual=1&__a=1&fb_dtsg="+fb_dtsg+"&lsd=&post_form_id="+post_form_id+"&post_form_id_source=AsyncRequest";
var request = { type: 'POST', url: url, data: { __a: 1, dual: 1, offset: offset, uid: uid }, dataType: "text", complete: function(data){
var response = data.responseText.match(/HTML.*$/)[0];
response = response.replace(/u003c/gi,"<");
response = response.replace(/\\u([a-f0-9]{4})/gm, "&#x$1;").replace(/\\\//g,"/").replace(/\\/g,'');
response = response.match(/^.*<\/div><\/div><\/div>/);
if(response != null){
response = response[0].replace("HTML(","");
var people = [];
$jq(response).find(".UIImageBlock").each( function(){
var newPerson = new Person( $jq(this).find('.UIImageBlock_Content a').text(), $jq(this).find('a').first().attr('href'), $jq(this).find('img').attr('src'), jQuery.parseJSON( $jq(this).find('a').last().attr('data-gt') ).engagement.eng_tid );
people.push( newPerson );
});
callback(people);
getMoreFriends(job, uid, fb_dtsg, post_form_id, offset+60, callback, finished);
}
} };
job.addToQueue( request );
if(job.state != "processing"){
if (typeof finished != "function" ){ finished = function(){}; }
job.startProcessing({ finished: function(){ finished(); } } );
}
}
您可以像这样从当前登录的用户那里获取必要的变量:
function loadFriends(person, onInit, store, callback){
info("loading friends of "+person.name+" initiated");
//addStatus("loading friends of "+person.name+" initiated");
if (typeof onInit == "function" ){
onInit();
}
if(person.id == -1){
error("Person "+person.name+" doesn't have an id.!");
addStatus("Person "+person.name+" doesn't have an id.!","error");
return false;
}
else {
// Load friends
var fb_dtsg = $jq('input[name="fb_dtsg"]').eq(0).val();
var post_form_id = $jq('#post_form_id').val();
var loadFriendsJob = ajaxManager.addJob({limit: 1});
getMoreFriends(loadFriendsJob,person.id, fb_dtsg, post_form_id, 0, function(people){ // callback on each iteration
d( "Loaded "+people.length+" friends of " + person.name );
store(people);
},function(){ // callback on finish
info("loading friends of "+person.name+" finished");
//addStatus("loading friends of "+person.name+" finished");
if (typeof callback == "function" ){ callback(); }
});
}
}
我知道这对您的情况可能没用,因为这是 JS。无论如何,有人可能会觉得这很有用。
PS:$jq = jQuery。PPS:那些作业对象负责处理顺序的 ajax 请求。我发现我需要它们,因为我的 FF 不想同时发出 2000 多个 AJAX 请求:-D