我可以使用此代码成功授权我的画布应用程序,但我只能获取用户 ID。我还需要用户名、年龄好友列表。请帮助我。
我使用了 Print_r 并得到了这个
Array ( [algorithm] => HMAC-SHA256 [expires] => 1366020000 [issued_at] => 1366012878 [oauth_token] => BAAFaFlrFWXYBADDEIui8rTtcEWldiZAGlHZB1mGSZoQ6E9fU9vkweYnx2jvj4SSDNRUd465YcAiz4hI3jlQlXLBmB0jVXZBeoAiSyO5P2TQoIQVt9SQRWVJEuTGtcyQzazZCi20MWhDqBsa1qgYWKloSRWOkKBdPDBZCI0exZA13Jygh73hsr9ldVvFy8ClgEb8jIZBblCArGT3lb7g [user] => Array ( [country] => pk [locale] => en_US [age] => Array ( [min] => 21 ) ) [user_id] => 100000
php代码
$app_id = " xxxxxxxxx";
$canvas_page = "xxxxxxxx";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), TRUE);
if(empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
print_r($data) ;
echo ("Welcome User: " . $data["user_id"]);
echo ("Welcome User: " . $data["age"]); //i tried this,but got undefined message?
}