我花了大约2个小时寻找使用Appcelerator Module.Facebook进行批量调用。我需要获取个人资料名称和图片。我想我想在一个HTTP请求中而不是两个中执行此操作。
经过深入研究,我终于找到了一种方法。我将在下面的答案部分发布我的答案。
万一其他人遇到这个..
var fb = require('facebook');
var log = require("log");
...
// After logging in
// gets user profile image and name uses a batch method example
function getUserInfo(userId) {
var batch = 'batch=[{"method":"GET", "relative_url":"me"},{"method":"GET", "relative_url":"me/picture"}]&access_token=' + fb.getAccessToken();
var url = "https://graph.facebook.com?" + batch;
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
log.args(this.responseText);
},
// function called when an error occurs, including a timeout
onerror : function(e) {
log.args(e.error);
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
client.open("POST", url);
// Send the request.
client.send();
}
这就是您使用 AppC 进行批量调用的方式,但是有一种更好的方法来获取我需要的信息。就我而言,我只需要Facebook名称和图片
function getGraphPath(userId) {
fb.requestWithGraphPath('me?fields=id,name,picture', {}, 'GET', function(e) {
if (e.success) {
log.args('Modules.Facebook.requestWithGraphPath', JSON.parse(e.result));
} else if (e.error) {
log.args(e.error);
} else {
log.args('Unknown response');
}
});
}