根據Facebook - Authentication within a Canvas Page Document,他們說我們將得到一個由一個JSON對象組成的signed_request
。現在他們說signed_request
可以通過$_POST['signed_request']
我同意它爲我工作。如何閱讀Facebook的signed_request獲取user_id
現在根據他們,如果用戶登錄我會得到這樣一個JSON對象值: -
{
"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",
...
}
}
現在我想取user_id
出這個所以我用這塊代碼但它不工作: -
if(isset($_POST['signed_request']))
{
echo 'YES';
$json = $_POST['signed_request'];
$obj = json_decode($json);
print $obj->{'user_id'};
}
它只是打印YES
。爲什麼這樣?
我讀過的地方沒有應用程序認證,我將無法提取user_id
,但根據facebook,這是第一步,認證應用程序將是第四。我對此很陌生,如果有人能幫助我,這將會非常有幫助。謝謝。
如果你做了一個'print_r($ _ POST)',你看到了什麼? – Brad 2012-08-15 16:35:08
當你嘗試'print_r($ _ POST)'時,你實際看到了什麼? – Brad 2012-08-15 16:38:23
@Brad當我'的print_r($ _ POST [ 'signed_request']);'我得到的正是這種價值'cnMQQpKShmtfcXXEAjNrazO7AZxAqCuZ0aIA-K1L-P8.qgytuisdhrl0aG0iOiJITUFDLVNIQTI1NiI sImV4cGlyZXMiOjEzNDUwNTM2MDAsImlzc3VlZF9hdCI6MTM0NTA0ODYwOCpoemi1dGhfdG9rZW4iOiJB QUFFOGZCWW1sN2NCQUJHVWZIb1VZUGdMcngwdjBURFlSdVFiNHNQR2pSMDRUNnZKZHkzWkFYU2RBYWNiV nFtMHJRZTFKZ2lrWkFRWkFJR2RPb0JuQ0JiVGxLOGpuUXlCSVpDWkJsWHdzWG5XbHg5VVZEV1dkIiwicG FnZSI6eyJpZCI6IjI2OTY3MDc5NjQ4MDcxOCIsImxpa2VkIjpmYWxzZSwiYWRtaW4iOmZhbHNlfSwidXN lciI6eyJjb3VudHJ5IjoiaW4iLCJsb2NhbGUiOiJlbl9JTiIsImFnZSI6eyJtaW4iOjIxfX0sInVzZXJf aWQiOiIxNTc2NDU1NjQ5In0' – 2012-08-15 16:39:39