0

We have an app running on a Facebook tab at the moment which is receiving a good deal of traffic. People are signing up every few seconds, and most are successful. However I am running into the following problems:

- access token not received at all (empty response, no error)
- or if it is received, then API call to /me fails (empty response, no error)

EDIT: Apparently limiting of API calls is not the issue, since the 600/600 calls/sec is per user which makes a lot more sense :).

Is anyone else experiencing such issues? I am getting about 20-30 successful app signups a minute and about 2-3 failing ones. Note: these are not users who deny access to the app - those are handled elsewhere...

EDIT: I am getting "failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request"

$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$oauth_clientid."&redirect_uri=".urlencode($redirect_url)."&client_secret=".$oauth_secret."&code=".$code;
$access_token = file_get_contents($token_url);
Aron
  • 3,419
  • 3
  • 30
  • 42
  • I'm not sure I understand, what do you mean by Facebook tab? Are you referring to the Page Tab, that is your application runs on a page? Also, the thing with the 600 request/seconds talks about doing all of those requests per access token, are you making that many requests per second for just one user? – Nitzan Tomer Feb 17 '12 at 18:33
  • Sorry, yes. Page Tab...but that's actually fairly irrelevant. :) – Aron Feb 17 '12 at 18:40
  • The requests are maybe one per second for the entire app. So I guess it is not the limit that is causing the issue. Also, with the limit I should be getting an error message as well, not an empty response! – Aron Feb 17 '12 at 18:42
  • How are you obtaining the access token for the user? And also, when you say that the api request returns with an empty response, do you mean completely empty of empty json object/array ? – Nitzan Tomer Feb 17 '12 at 18:45
  • I mean completely empty. No JSON data. No error. I have not yet checked the headers, but there is no document data. – Aron Feb 17 '12 at 18:53
  • This is what I am getting: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request – Aron Feb 17 '12 at 19:00
  • Can you post some pieces of your code so it will be possible to see what you're doing and why it fails – Nitzan Tomer Feb 17 '12 at 19:06
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7863/discussion-between-aron-and-nitzan-tomer) – Aron Feb 17 '12 at 19:11

3 Answers3

1

Update: After modifying my code to use curl, there was some improvement, but it did not resolve the issue. The application in question is now past its peak usage, so obviously the number of errors have gone down drastically. It still happens sometimes. The errors are (most often):

  • Curl error (6): Couldn't resolve host 'graph.facebook.com'
  • Curl error (28): SSL connection timeout

...and other similar errors.

From my experience with a week or two of data, it seems to effect about a percent of requests when there is high traffic, less when there is low - but this is quite unscientific. :)

--

So the solution? Well there is none really. It seems that some percent of requests will fail and my (your) application needs to handle these errors as elegantly as possible.

My only question is, has anyone else had such experience with high traffic apps? (meaning in this case 100 000-500 000 daily pageviews and 50 000-100 000 active users)

Aron
  • 3,419
  • 3
  • 30
  • 42
0

Try to log the curl error and return value when you obtain the access_token the answer should be there.

Sándor Tóth
  • 743
  • 4
  • 10
  • I was using file_get_contents up until now. A curl version of the code just went live about an hour ago, but I already have a "Curl error (6): Couldn't resolve host 'graph.facebook.com'". On occassion this is normal I assume, so I will have to wait another day to see how often this happens... – Aron Feb 18 '12 at 23:04
0

I think it's because php_openssl extension is either absent or disabled. See this question to enable it. Or you can use cURL. Take fb_ca_chain_bundle.crt from PHP SDK official (or set CURLOPT_SSL_VERIFYPEER to false):

$base_url = 'https://graph.facebook.com/oauth/access_token';
$params   = array();

$params['client_id']     = $client_id;
$params['client_secret'] = $client_secret;
$params['redirect_uri']  = $redirect_uri;
$params['code']          = $code;

$options = array(
    CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_CAINFO         => __DIR__ .'/fb_ca_chain_bundle.crt',
    CURLOPT_RETURNTRANSFER => true,
    CURLINFO_HEADER_OUT    => false,
    CURLOPT_HEADER         => false,
    CURLOPT_URL            => $base_url . '?' . http_build_query($params),
 );

 // Init cURL and send the request
 $ch = curl_init();
 curl_setopt_array($ch, $params);

 $result = curl_exec($ch);
 $infos  = curl_getinfo($ch);

 curl_close($ch);
 var_dump($result, $infos);

EDIT: i warn you this is a quick copy and paste from my code so you would double check $options.

Community
  • 1
  • 1
gremo
  • 47,186
  • 75
  • 257
  • 421
  • Wouldn't it make sense that then NO requests work? It is very strange that most of my requests (95%) go through just fine. And its not even a user-setting thing (such as HTTPS) since retrying a few times it eventually works... Regardless I will give this a try... – Aron Feb 17 '12 at 21:51
  • also check out this http://stackoverflow.com/questions/6903240/getting-404-error-from-facebook-graph-api – Nitzan Tomer Feb 17 '12 at 22:40
  • @Aron sorry, didn't read your question very well. Yes it's strange that you're getting random 400 errors. Since only params can vary i would log params at each request to investigate further. – gremo Feb 18 '12 at 01:06