好的,我正在开发一个可以加载更多结果的Facebook群组Feed,但是我在构建初始查询时遇到了麻烦。
在下面的第一个if
语句中,您可以看到我将查询的各个部分放入变量的位置,然后调用该函数,传递这些变量。这一切都很好......
if (response.status === 'connected') {
// Logged into your app and Facebook.
console.log('Welcome! Fetching your information.... ');
var path = '/',
method = 'POST',
params = {
batch: [
{method : 'GET', name : 'user', relative_url : '/me?fields=id,name,picture'},
{method: 'GET', name : 'post-ids', relative_url: '/group-id/feed?fields=fields{with field expansion}',omit_response_on_success : false}
]
};
loadFeed(path, method, params);
}
下面的功能是我遇到麻烦的地方。第一次调用该函数时,我需要将这三个变量放在一起,并用FB.api调用它。你可以在这里看到这个功能:
function loadFeed(path, method, params) {
console.log('------------------');
console.log(path + ', ' + method + ', ' + params);
if(path != 'undefined') {
if(method != 'undefined') {
if(params != 'undefined') { var query = '{\'' + path + '\', \'' + method + '\', ' + params + '}'; }
}
else { var query = path; }
}
$('#load-more').css('display', 'hidden');
FB.api(query, function (response) {
console.log(response);
// first time page loads, response[0] is the login, and response[1] is the feed
// each time after that, response[0] is the feed
if(response.length > 1) {
var membody = JSON.parse(response[0].body),
feed = JSON.parse(response[1].body);
} else {
var feed = JSON.parse(response);
}
if(feed.paging) {
if(feed.paging.next) {
var load_more = '<div id="load-more"><center>Load more</center></div>',
method = '',
params = '';
$('#feed').append(load_more);
$('#load-more').click( function() {
loadFeed(feed.paging.next);
});
}
}
});
}
在第一次调用此函数时,我收到此错误:
error: Object
code: 2500
message: "Unknown path components: /', 'POST', [object Object]}"
type: "OAuthException"
这似乎告诉我,我基本上把查询放错了,但是我尝试了一些不同的东西,但没有一个是有效的。您可以在错误消息中看到查询开头缺少单引号,而且我无法弄清楚如何在那里保留单引号。
有没有人对如何解决这个问题有任何想法?
另外,如果你知道一个更好的方法来做这一切,那么我也很感激!
答案 0 :(得分:1)
您似乎正在使用HTTP API参数构建Javascript API调用。
为用户查询JS API:
FB.api(
"/me", // or "/99999999999" the user's id
function(response) {
if (response && !response.error) {
/* handle the result */
}
);
资料来源:https://developers.facebook.com/docs/graph-api/reference/v2.2/user
查询组的JS API:
FB.api(
"/{group-id}",
function(response) {
if (response && !response.error) {
/* handle the result */
}
}
);
资料来源:https://developers.facebook.com/docs/graph-api/reference/v2.2/group