Sorry for this silly question but I really can't get it working. I am using the following code to exchange a 2-hour facebook token for a long lived. My token are stored in mysql table offline_users.When I paste the token manually, the script works perfectly and gives me the 60-day token, but when I select the token from mysql it doesn't work. Following is my code. I hope you can help me find my mistake.
<?php
include("lib/db.php");
$id=$_GET['id'];
$reponse = mysql_query("SELECT * FROM offline_access_users WHERE id=$id;");
$app_id = "xxxxxxxxxxxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "https://apps.facebook.com/xxxxxxxxxxxxxxxxxxxxxx";
$code = $donnees['access_token'];
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxx&%20client_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX0&%20grant_type=fb_exchange_token&%20fb_exchange_token=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$longtoken=$params['access_token'];
echo $longtoken;
mysql_query(
"UPDATE
offline_access_users
SET
`access_token` = '" . mysql_real_escape_string($longtoken) . "'
WHERE
`id` = $id
");
//save it to database
?>