facebook access token expired
up vote
5
down vote
favorite
Based on facebook instructions (Scenario 4) i am using the following URL
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET& grant_type=fb_exchange_token&fb_exchange_token=OLD_ACCESS_TOKEN
to get the new access token but i get the following:
"error":
"message": "Error validating access token: Session has expired at unix time 1365257820. The current unix time is 1365759029.",
"type": "OAuthException",
"code": 190,
"error_subcode": 463
does not work. Any help appreciated.
EDIT: Got it! Works like this
if access token expires run the below php script first on the browser after you store it on your server
<?php
$app_id = "your app id";
$app_secret = "your app secret";
$my_url = "http://apps.facebook.com/your_app_name";
// known valid access token stored in a database
$access_token = "your old access token";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code))
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error)
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException")
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
else
echo "other error has happened";
else
// success
echo("success" . $decoded_response->name);
echo($access_token);
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL)
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
?>
the above script will give you a URL like the one below on the browser
https://graph.facebook.com/oauth/access_token?code=…
then get the string (should be something like this: AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_ )
after code= and paste it on the code= URL below and RUN the URL below on the browser
https://graph.facebook.com/oauth/access_token?client_id=App_Id&redirect_uri=http://apps.facebook.com/poemsoflove&client_secret=App_Secret&code=AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_&display=popup
you will get the following respond which is a new access token for 60 days
access_token=<Extended_Access_Token>&expires=5180130
copy and paste the string after the access_token= to the script on your server that publishes the new posts on your page
facebook access-token facebook-access-token
add a comment |
up vote
5
down vote
favorite
Based on facebook instructions (Scenario 4) i am using the following URL
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET& grant_type=fb_exchange_token&fb_exchange_token=OLD_ACCESS_TOKEN
to get the new access token but i get the following:
"error":
"message": "Error validating access token: Session has expired at unix time 1365257820. The current unix time is 1365759029.",
"type": "OAuthException",
"code": 190,
"error_subcode": 463
does not work. Any help appreciated.
EDIT: Got it! Works like this
if access token expires run the below php script first on the browser after you store it on your server
<?php
$app_id = "your app id";
$app_secret = "your app secret";
$my_url = "http://apps.facebook.com/your_app_name";
// known valid access token stored in a database
$access_token = "your old access token";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code))
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error)
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException")
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
else
echo "other error has happened";
else
// success
echo("success" . $decoded_response->name);
echo($access_token);
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL)
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
?>
the above script will give you a URL like the one below on the browser
https://graph.facebook.com/oauth/access_token?code=…
then get the string (should be something like this: AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_ )
after code= and paste it on the code= URL below and RUN the URL below on the browser
https://graph.facebook.com/oauth/access_token?client_id=App_Id&redirect_uri=http://apps.facebook.com/poemsoflove&client_secret=App_Secret&code=AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_&display=popup
you will get the following respond which is a new access token for 60 days
access_token=<Extended_Access_Token>&expires=5180130
copy and paste the string after the access_token= to the script on your server that publishes the new posts on your page
facebook access-token facebook-access-token
1
This means that your old access token has already expired. Could you retry the same thing with a new short lived access token
– Anvesh Saxena
Apr 12 '13 at 9:57
thanks i have done it with a new short lived access token
– stefanosn
Apr 12 '13 at 10:29
3
You just wrote the access token to the world, please be careful about it. Anyone can misuse it.
– Anvesh Saxena
Apr 12 '13 at 11:31
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
Based on facebook instructions (Scenario 4) i am using the following URL
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET& grant_type=fb_exchange_token&fb_exchange_token=OLD_ACCESS_TOKEN
to get the new access token but i get the following:
"error":
"message": "Error validating access token: Session has expired at unix time 1365257820. The current unix time is 1365759029.",
"type": "OAuthException",
"code": 190,
"error_subcode": 463
does not work. Any help appreciated.
EDIT: Got it! Works like this
if access token expires run the below php script first on the browser after you store it on your server
<?php
$app_id = "your app id";
$app_secret = "your app secret";
$my_url = "http://apps.facebook.com/your_app_name";
// known valid access token stored in a database
$access_token = "your old access token";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code))
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error)
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException")
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
else
echo "other error has happened";
else
// success
echo("success" . $decoded_response->name);
echo($access_token);
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL)
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
?>
the above script will give you a URL like the one below on the browser
https://graph.facebook.com/oauth/access_token?code=…
then get the string (should be something like this: AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_ )
after code= and paste it on the code= URL below and RUN the URL below on the browser
https://graph.facebook.com/oauth/access_token?client_id=App_Id&redirect_uri=http://apps.facebook.com/poemsoflove&client_secret=App_Secret&code=AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_&display=popup
you will get the following respond which is a new access token for 60 days
access_token=<Extended_Access_Token>&expires=5180130
copy and paste the string after the access_token= to the script on your server that publishes the new posts on your page
facebook access-token facebook-access-token
Based on facebook instructions (Scenario 4) i am using the following URL
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET& grant_type=fb_exchange_token&fb_exchange_token=OLD_ACCESS_TOKEN
to get the new access token but i get the following:
"error":
"message": "Error validating access token: Session has expired at unix time 1365257820. The current unix time is 1365759029.",
"type": "OAuthException",
"code": 190,
"error_subcode": 463
does not work. Any help appreciated.
EDIT: Got it! Works like this
if access token expires run the below php script first on the browser after you store it on your server
<?php
$app_id = "your app id";
$app_secret = "your app secret";
$my_url = "http://apps.facebook.com/your_app_name";
// known valid access token stored in a database
$access_token = "your old access token";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code))
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error)
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException")
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
else
echo "other error has happened";
else
// success
echo("success" . $decoded_response->name);
echo($access_token);
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL)
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
?>
the above script will give you a URL like the one below on the browser
https://graph.facebook.com/oauth/access_token?code=…
then get the string (should be something like this: AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_ )
after code= and paste it on the code= URL below and RUN the URL below on the browser
https://graph.facebook.com/oauth/access_token?client_id=App_Id&redirect_uri=http://apps.facebook.com/poemsoflove&client_secret=App_Secret&code=AQCn41Svv5DbWrnFY0Wf.....YbNm_yz2rE#_&display=popup
you will get the following respond which is a new access token for 60 days
access_token=<Extended_Access_Token>&expires=5180130
copy and paste the string after the access_token= to the script on your server that publishes the new posts on your page
facebook access-token facebook-access-token
facebook access-token facebook-access-token
edited Jan 8 '14 at 11:30
Alexander Farber
8,04155187326
8,04155187326
asked Apr 12 '13 at 9:34
stefanosn
1,13093159
1,13093159
1
This means that your old access token has already expired. Could you retry the same thing with a new short lived access token
– Anvesh Saxena
Apr 12 '13 at 9:57
thanks i have done it with a new short lived access token
– stefanosn
Apr 12 '13 at 10:29
3
You just wrote the access token to the world, please be careful about it. Anyone can misuse it.
– Anvesh Saxena
Apr 12 '13 at 11:31
add a comment |
1
This means that your old access token has already expired. Could you retry the same thing with a new short lived access token
– Anvesh Saxena
Apr 12 '13 at 9:57
thanks i have done it with a new short lived access token
– stefanosn
Apr 12 '13 at 10:29
3
You just wrote the access token to the world, please be careful about it. Anyone can misuse it.
– Anvesh Saxena
Apr 12 '13 at 11:31
1
1
This means that your old access token has already expired. Could you retry the same thing with a new short lived access token
– Anvesh Saxena
Apr 12 '13 at 9:57
This means that your old access token has already expired. Could you retry the same thing with a new short lived access token
– Anvesh Saxena
Apr 12 '13 at 9:57
thanks i have done it with a new short lived access token
– stefanosn
Apr 12 '13 at 10:29
thanks i have done it with a new short lived access token
– stefanosn
Apr 12 '13 at 10:29
3
3
You just wrote the access token to the world, please be careful about it. Anyone can misuse it.
– Anvesh Saxena
Apr 12 '13 at 11:31
You just wrote the access token to the world, please be careful about it. Anyone can misuse it.
– Anvesh Saxena
Apr 12 '13 at 11:31
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
- Create application Facebook Developer Page
After with php can get live access toke
$app_id = 'Application Id';
$app_secret = 'Application Secret';
$access_token = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token = file_get_contents($access_token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'
$access_token = str_replace('access_token=', '', $access_token);
add a comment |
up vote
0
down vote
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$access_token_url = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token_data = file_get_contents($access_token_url);
$access_token_arr = json_decode($access_token_data);
$access_token = $access_token_arr->access_token;
3
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
- Create application Facebook Developer Page
After with php can get live access toke
$app_id = 'Application Id';
$app_secret = 'Application Secret';
$access_token = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token = file_get_contents($access_token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'
$access_token = str_replace('access_token=', '', $access_token);
add a comment |
up vote
0
down vote
- Create application Facebook Developer Page
After with php can get live access toke
$app_id = 'Application Id';
$app_secret = 'Application Secret';
$access_token = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token = file_get_contents($access_token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'
$access_token = str_replace('access_token=', '', $access_token);
add a comment |
up vote
0
down vote
up vote
0
down vote
- Create application Facebook Developer Page
After with php can get live access toke
$app_id = 'Application Id';
$app_secret = 'Application Secret';
$access_token = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token = file_get_contents($access_token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'
$access_token = str_replace('access_token=', '', $access_token);
- Create application Facebook Developer Page
After with php can get live access toke
$app_id = 'Application Id';
$app_secret = 'Application Secret';
$access_token = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token = file_get_contents($access_token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'
$access_token = str_replace('access_token=', '', $access_token);
edited Aug 13 '16 at 16:08
answered Aug 13 '16 at 15:54
Ramin Darvishov
804818
804818
add a comment |
add a comment |
up vote
0
down vote
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$access_token_url = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token_data = file_get_contents($access_token_url);
$access_token_arr = json_decode($access_token_data);
$access_token = $access_token_arr->access_token;
3
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
add a comment |
up vote
0
down vote
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$access_token_url = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token_data = file_get_contents($access_token_url);
$access_token_arr = json_decode($access_token_data);
$access_token = $access_token_arr->access_token;
3
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
add a comment |
up vote
0
down vote
up vote
0
down vote
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$access_token_url = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token_data = file_get_contents($access_token_url);
$access_token_arr = json_decode($access_token_data);
$access_token = $access_token_arr->access_token;
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$access_token_url = "https://graph.facebook.com/oauth/access_token?client_id=$app_id&client_secret=$app_secret&grant_type=client_credentials";
$access_token_data = file_get_contents($access_token_url);
$access_token_arr = json_decode($access_token_data);
$access_token = $access_token_arr->access_token;
answered Jul 21 '17 at 4:07
Suneesh Mohanan
92
92
3
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
add a comment |
3
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
3
3
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
Please don't just post some code as answer. Kindly explain your logic.
– Harsh Wardhan
Jul 21 '17 at 5:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15967821%2ffacebook-access-token-expired%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This means that your old access token has already expired. Could you retry the same thing with a new short lived access token
– Anvesh Saxena
Apr 12 '13 at 9:57
thanks i have done it with a new short lived access token
– stefanosn
Apr 12 '13 at 10:29
3
You just wrote the access token to the world, please be careful about it. Anyone can misuse it.
– Anvesh Saxena
Apr 12 '13 at 11:31