您没有提供示例或测试用例,也没有提供任何可使用的 API 代码。我将以 Facebook 用户名Hostess的以下链接为例(Twinkies 万岁!):
主要:https
://www.facebook.com/Hostess相册:https ://www.facebook.com/Hostess/photos_albums
首先,我们需要 Facebook 用户编号。
您可以执行GET
请求或在浏览器中输入:
Facebook 用户信息: http: //graph.facebook.com/Hostess
为了继续这个例子,我们将使用上一步提供的 Facebook 号码:
Facebook ID:145369525544570
有没有办法通过 Facebook API (graph/fql) 获取 Facebook 相册的公共链接,可以与不在 Facebook 上的人共享?
是的,有办法!此链接将为您提供json
所有专辑的结果,在本例中为 6:
Facebook 专辑,来自json
: http: //graph.facebook.com/145369525544570/albums
要限制返回的结果,您可以使用?limit=1
(其中 1 是返回的专辑数量):
Facebook Album (1) via json
:http ://graph.facebook.com/145369525544570/albums?limit=1
此专辑不可公开访问。它受用户设置的相册共享权限的限制。但我正在寻找一种方法来生成此受限相册的公共链接,以便发送此链接的任何人都可以无条件地查看相册。
你运气不好,没有办法。但是,您无需成为 Facebook 会员即可查看相册中的图像。当相册公开时,可以使用json
上一步中的数据。只需使用一个简单的请求:GET
jsFiddle DEMO:来自 Facebook ID 的 Facebook 相册链接
// Console log messages are provided, activate your browsers console.
$.ajax({
url: 'http://graph.facebook.com/145369525544570/albums',
dataType: "json",
success: function(yourVar) {
// Make sure the request, 1 json object, was returned.
if (yourVar) {
console.log('This is the jQuery Object received. Click on it to explore contents');
console.log(yourVar);
// This will parse the Objects received in 'data' variable.
// Having said that, it's coincidental the data the wrapped in a 'data' name.
$(yourVar.data).each(function(index) {
// Only process Objects that have valid Album links.
// Having said that, only Photo Albums are returned in initial data, not Video Albums.
if(this.link){
// Display in console the jQuery zero indexed number
console.info('Album Index object: ' + index);
//
// Display in HTML via append, the same information.
$('body').append('<b>Album Index Object: </b>' + index + '<br />');
// Display in console the Album Names available
console.info('Name: ' + this.name);
//
// Display in HTML via append, the same information.
$('body').append('<b>Name: </b>' + this.name + '<br />');
// Display in console the Album Name Url;
console.log('Url: ' + this.link);
//
// Display in HTML via append, the same information.
$('body').append('<b>Url: </b>' + this.link + '<br />');
// Display in console dashed lines before next item is shown.
console.log('-------');
//
// Display in HTML via append, the same information.
$('body').append('<hr><br /><br />');
}
});
} else {
console.log('Was data expected? Check your jQuery or JavaScript for errors.');
}
}
});
// Power-Tip!
// You can also use .ajax() with a YQL Rest Query url.
// See YQL Console with Rest Statement at:
// http://developer.yahoo.com/yql/console/?q=SELECT%20data.link%20FROM%20json%20WHERE%20url%3D%22https%3A%2F%2Fgraph.facebook.com%2F145369525544570%2Falbums%22&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
// As seen there, the data.link is providing just the links.
// Change data.link to * to see all data nodes available in json tree.
// That being said, your .ajax() url for above is at the bottom: The Rest Query.