Facebook graph api 使用facebook API解析云代码无法正常工作
我想从FacebookAPI(已经在我的数据库中)获取一个位置Id,然后使用它从该位置获取事件 因此,我首先运行一个查询来获取此信息,然后将此结果作为参数添加到我的url中。事实上,查询正确地返回了结果,但在调用httpRequest时,这是失败的。重要的是,当我使用locationId硬编码时,我的httpRequest可以工作 我猜这个问题是因为响应电话而发生的,但我不知道如何解决它。我也在寻找一种更好的方法来设计这段代码。有什么想法吗Facebook graph api 使用facebook API解析云代码无法正常工作,facebook-graph-api,parse-platform,Facebook Graph Api,Parse Platform,我想从FacebookAPI(已经在我的数据库中)获取一个位置Id,然后使用它从该位置获取事件 因此,我首先运行一个查询来获取此信息,然后将此结果作为参数添加到我的url中。事实上,查询正确地返回了结果,但在调用httpRequest时,这是失败的。重要的是,当我使用locationId硬编码时,我的httpRequest可以工作 我猜这个问题是因为响应电话而发生的,但我不知道如何解决它。我也在寻找一种更好的方法来设计这段代码。有什么想法吗 Parse.Cloud.define("hello",
Parse.Cloud.define("hello", function(request, response) {
var query = new Parse.Query("Location");
query.find({
success: function(results) {
locationId = results[0].get("locationFbId");
console.log(locationId);
},
error: function() {
response.error("Failed on getting locationId");
}
});
Parse.Cloud.httpRequest({
url: 'https://graph.facebook.com/v2.2/'+locationId+'/events?access_token='+accessToken,
success: function(httpResponse) {
console.log(httpResponse.data);
response.success("result");
},
error:function(httpResponse){
console.error(httpResponse.message);
response.error("Failed to get events");
}
});
});
Adolfosrs,这里的问题是您的两个请求在不同的线程上异步运行。因此,在调用第二个请求之前,第一个请求不会返回。我建议如下链接请求,以便使用从第一个请求检索到的数据初始化第二个请求
Parse.Cloud.define("hello", function(request, response) {
var query = new Parse.Query("Location");
query.find({
success: function(results) {
locationId = results[0].get("locationFbId");
console.log(locationId);
Parse.Cloud.httpRequest({
url: 'https://graph.facebook.com/v2.2/'+locationId+'/events?access_token='+accessToken,
success: function(httpResponse) {
console.log(httpResponse.data);
response.success("result");
},
error:function(httpResponse){
console.error(httpResponse.message);
response.error("Failed to get events");
}
});
},
error: function() {
response.error("Failed on getting locationId");
}
});
});