Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting to Facebook Graph Api is slow

I am creating a new Facebook app and there are actions attached to it, like the 'Listening to xxx' on Spotify.

Trouble is that the call takes around 6-7 seconds which is quite a long time. Beneath my code is the results of curl_getinfo. Is it supposed to be this slow?

    $attachment = array(
        'access_token' => $access_token,
        'album' => 'sergeant peppers',
    );

    $opts = array(
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 60,
        CURLOPT_USERAGENT => 'facebook-php-3.1',
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $attachment,
        CURLOPT_URL => 'https://graph.facebook.com/me/APPNAME:listening'
    );
    $ch = curl_init();
    curl_setopt_array($ch, $opts);
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

The results of curl_getinfo:

[url] => https://graph.facebook.com/me/APPNAME:listening
[content_type] => text/javascript; charset=UTF-8
[http_code] => 400
[header_size] => 557
[request_size] => 238
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 6.002449
[namelookup_time] => 0.024892
[connect_time] => 0.179322
[pretransfer_time] => 0.77444
[size_upload] => 362
[size_download] => 212
[speed_download] => 35
[speed_upload] => 60
[download_content_length] => 212
[upload_content_length] => 362
[starttransfer_time] => 1.775707
[redirect_time] => 0
[certinfo] => Array
    (
    )

[redirect_url] => 
like image 761
bluedaniel Avatar asked Apr 04 '12 15:04

bluedaniel


1 Answers

Well, you have gotten a http 400 return (bad request), which indicates something went wrong. Maybe if you get your request right the request will be faster?

This post: php cURL error in facebook api indicates that you should remove 'CURLOPT_POST => true' I also suggest adding 'CURLOPT_VERIFYPEER => false' if you still have problems.

like image 130
jornare Avatar answered Oct 19 '22 20:10

jornare