Graph api (facebook) 太慢
当我使用 Graph API 执行简单操作时,例如:(
require 'src/facebook.php';
# facebook class
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'XXX',
));
for ($i = 0; $i < 9; $i++)
{
$url = $facebook->api('/Intel');
echo $url['name'] . '<br />';
}
只是一个简单的示例,我想返回 9 个不同的页面,但现在并不重要)
好吧,这个操作花了 9 - 10 秒!太多了..这是页面上唯一的操作(您可以尝试运行它并查看)。
我能做些什么? (如果我通过 api [作为方法 fql.query] 使用 FQL,它不会提高运行时间,我检查了它)我必须使用图形 api。
顺便说一句,我正在使用 PHP SDK 3.0.1(最新版本..也许这就是问题所在?)
While I'm using the Graph API to simple action, like this for example:
require 'src/facebook.php';
# facebook class
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'XXX',
));
for ($i = 0; $i < 9; $i++)
{
$url = $facebook->api('/Intel');
echo $url['name'] . '<br />';
}
(just a quick example, I want to return 9 different pages but it doesn't matter now)
Well, this action took 9 - 10 SECONDS! too much.. and this is the only acion on the page (you can try run it and see).
What can I do? (if I'm using FQL via api [as method fql.query] it doesn't improve the running time, I checked it) I have to using graph api.
By the way, I'm using PHP SDK 3.0.1 (newest version.. maybe this is the problem?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否意识到您正在循环进行远程调用?它会一一进行多个远程调用,这就是它慢的原因。 API 太快了。
我建议您在这里使用 FQL 并批量发送多个查询。通过这种方式,您可以进行一次远程调用并同时获取多个查询的数据。
我总是建议使用应用程序。最好是阻止您的应用程序,以防出现问题,而不是 IP。
Do you realize that you are making a remote call in a loop? It will make several remote calls one by one, thats why its slow. API is damn fast.
What I would suggest you is to use FQL here and send multiple queries in batch. This way you make one remote call and get data of several queries together.
And I would always recommend using an app. Its better to get your app blocked in case something goes wrong instead of IP.
对于图 api 的这一部分,您不需要该 api,因此不要使用它。只需通过curl 获取
http://graph.facebook.com/Intel
并对其进行json_decode 即可。或者如果你可以使用它
for this part of the graph api you dont need the api, so dont use it. just fetch
http://graph.facebook.com/Intel
via curl and json_decode it.or if you can use it