我正在尝试使用 casperJS 调用 facebook API,使用如下网址:
https://graph.facebook.com/<APP_ID>/accounts/test-users?installed=false&name=Joe&locale=en_US&method=post&access_token=<ACCESS_TOKEN>
当我将它放入浏览器中时,它工作正常(我得到了完美的 JSON 结果),但是当我尝试在 casperJS 脚本中访问它时,我得到一个 about:blank 页面。我尝试过各种方法:
casper.open(url);
casper.open(url, { method: 'post' });
casper.open(url, { method: 'get' }); // even though it should be a post...
casper.open(url, { method: 'put' }); // still trying stuff
casper.open(baseUrl, { method: 'post', data: { ... } });
当我获取当前url时,它是about:blank,当我获取内容时,它只是一个空页面:
<html><head></head><body></body></html>
最佳答案
var casper = require('casper').create();
var url = '<your url here>';
casper.start().then(function() {
this.open(url, {
method: 'get',
headers: {
'Accept': 'application/json'
}
});
});
casper.run(function() {
require('utils').dump(JSON.parse(this.getPageContent()));
this.exit();
});
关于javascript - 从 CasperJS 调用 Facebook API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16464895/