I am trying to develop an Facebook application (apps.facebook.com/some_app) using PHP where I need to present some information based on user's music interests. I found that its under "user_likes > games".
My problems are as follows:
- To gain access, I have implemented the oauth dialog method as
suggested in API in my index page.
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri="
. urlencode($canvas_page)
."&scope=user_likes";
- After successful authorization I come back to index page with "code"
as parameters.
http://MY_CANVAS_PAGE/?code=some base64 encoded letters
- Firstly I don't know if I need access_token just to read user's music
interests but I have tried all the methods suggested. I couldn't move
forward from this point
- I have a code like this (in my index page), which redirects for authorization if code parameters is not set.
if(empty($code) && !isset($_REQUEST['error'])) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
echo("<script> top.location.href='" . $auth_url . "'</script>");
}
- Currently I am just trying to get user's public information here but
with no success. I have tried the signed_request method as suggested
but no success
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
echo ("Welcome User: " . $data["user_id"]);
print_r($decoded_response);
stdClass Object ( [error] => stdClass Object ( [message] => An active
access token must be used to query information about the current user.
[type] => OAuthException [code] => 2500 ) )
To get user's public info, I have tried also the suggested example in PHP SDK
$facebook = new Facebook(array(
'appId' => MY_APP_ID, //registered facebook APP ID
'secret' => MY_SECRET, //secret key for APP
));
$fb_user = $facebook->getUser();
if($fb_user){
try {
$user_profile = $facebook->api('/me');
echo $user_profile['email'];
}
catch(FacebookApiException $e) {
$fb_user = null;
}
}
But no success. Can somebody explain me why I am getting this error and how to access the user's music interest properly. Probably I misunderstood the API.
Thanks
Deepak
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…