I
I
Ivan Polikarpov2014-04-02 19:47:20
PHP
Ivan Polikarpov, 2014-04-02 19:47:20

Why is Graph.facebook.com/me returning true?

The second day I am at war with the FB Graph API :)
I don’t want to use the PHP SDK, because there is something very confused with sessions and I couldn’t implement it in CI in a day. Accordingly, I write myself. And more useful, and clearer.
At the moment, it seems like it turned out with authorization, at least I get the correct access_token.
I want to write it to the database for further procedures (I plan to post it in the account and user pages), but I need the user's fb_id.
Immediately after receiving the token, I try to send a request to the API, the method looks something like this:

$graph_url= "https://graph.facebook.com/me";
$appsecret_proof= hash_hmac('sha256', $access_token, $client_secret);
$postData = '';
$postData = "&appsecret_proof=" .$appsecret_proof;
$postData .= "&access_token=".$access_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php-3.2');
$output = curl_exec($ch);
curl_close($ch);
return ($output);

The only problem is that the result is "true" instead of a json object with user data.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Polikarpov, 2014-04-03
@taboo1387

Now, the correct answer is:

$add = http_build_query($params, NULL, '&');
$graph_url= "https://graph.facebook.com".$request.'?'.$add;
$appsecret_proof= hash_hmac('sha256', $access_token, $client_secret);
$postData = '';
$postData = "&appsecret_proof=" .$appsecret_proof;
$postData .= "&access_token=".$access_token;
$ch = curl_init($graph_url.$postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question