use*_*931 2 javascript api facebook social-networking facebook-graph-api
我使用Facebook API浏览相册,选择相册,然后将照片输出到我的页面.
我在Facebook上成功登录.接受应用权限.它将所有专辑输出到页面以供选择.我选择一个相册并将相册ID传递到我输出照片的另一个页面.但是响应并没有所有的照片字段,只有id和created_time.
例如:
//load fb api
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
//Initialise
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXX',
status : true,
xfbml : true,
cookie : true,
version : 'v2.4'
});
}
//Get albums - This works fine.
FB.api( "/me/albums", function (response) {
if (response && !response.error) {
data = response.data;
//Output albums...
}
});
Run Code Online (Sandbox Code Playgroud)
我选择一张专辑并将其传递到我输出照片的页面,如下所示:
FB.api(
"/ALBUM_ID/photos",
function (response) {
if (response && !response.error) {
console.log(response);
}
}
);
Run Code Online (Sandbox Code Playgroud)
这就是它破裂的地方.日志中的输出如下所示:
Object {data: Array[1], paging: Object}
data: Array[1]
0: Object
created_time: "2014-05-07T10:39:31+0000"
id: "xxxxxxxxxxxxxxx"
Run Code Online (Sandbox Code Playgroud)
就是这样.没有其他领域.日志中没有错误.我不明白为什么我只得到一些数据.
Graph API v2.4减少了默认响应中的字段数.
https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/
更少的默认字段可提高性能:为了帮助提高移动网络连接的性能,我们减少了默认情况下API返回的字段数.您现在应该使用
?fields=field1,field2语法来声明您希望API返回的所有字段.
简而言之,明确说明您在请求中需要哪些字段.