According to Facebook - Authentication within a Canvas Page Document, they say that we will be getting a signed_request
which consists a JSON object. Now they say that signed_request
can be get through $_POST['signed_request']
I agree its working for me.
Now according to them if the user is logged in i will be getting a JSON object value like this:-
{
"expires":UNIXTIME_WHEN_ACCESS_TOKEN_EXPIRES,
"algorithm":"HMAC-SHA256",
"issued_at":UNIXTIME_WHEN_REQUEST_WAS_ISSUED,
"oauth_token":"USER_ACCESS_TOKEN",
"user_id":"USER_ID",
"user":{
"country":"ISO_COUNTRY_CODE",
"locale":"ISO_LOCALE_CODE",
...
}
}
Now i want to fetch the user_id
out of this so i am using this piece of code but its not working:-
if(isset($_POST['signed_request']))
{
echo 'YES';
$json = $_POST['signed_request'];
$obj = json_decode($json);
print $obj->{'user_id'};
}
It just print the YES
. Why is it so?
I have read somewhere that without app authentication i will not be able to extract the user_id
but according to the facebook, this is the 1st step and authenticating the application would be 4th. I am new to it, if somebody can please help me, it will be of great help. Thanks.
print_r($_POST)
, what do you see? – Garibaldprint_r($_POST)
? – Garibaldprint_r($_POST['signed_request']);
i get exactly this valuecnMQQpKShmtfcXXEAjNrazO7AZxAqCuZ0aIA-k1L-P8.qgytuisdhrl0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEzNDUwNTM2MDAsImlzc3VlZF9hdCI6MTM0NTA0ODYwOCpoemi1dGhfdG9rZW4iOiJBQUFFOGZCWW1sN2NCQUJHVWZIb1VZUGdMcngwdjBURFlSdVFiNHNQR2pSMDRUNnZKZHkzWkFYU2RBYWNiVnFtMHJRZTFKZ2lrWkFRWkFJR2RPb0JuQ0JiVGxLOGpuUXlCSVpDWkJsWHdzWG5XbHg5VVZEV1dkIiwicGFnZSI6eyJpZCI6IjI2OTY3MDc5NjQ4MDcxOCIsImxpa2VkIjpmYWxzZSwiYWRtaW4iOmZhbHNlfSwidXNlciI6eyJjb3VudHJ5IjoiaW4iLCJsb2NhbGUiOiJlbl9JTiIsImFnZSI6eyJtaW4iOjIxfX0sInVzZXJfaWQiOiIxNTc2NDU1NjQ5In0
– Mai$signed_request = $facebook->getSignedRequest();
– Weakwilled