By default, the access tokens (OAuth Token) you receive from the Facebook Platform are session-length only. So, what you describe is expected.
Up vote 1 down vote favorite share g+ share fb share tw.
I'm currently using the PHP Facebook SDK for my project (github.com/facebook/php-sdk/). I have set it up so that a user will have to click a link to visit Facebook, which will then verify the user to use the application, and then return the session details to my site, which is fine. However, I want to store these session details within a database so that the user on logging in, can access information from their account at any time.
Currently, if the user logs out of Facebook, and then tries to retrieve information from my site, I get the following exception "OAuthInvalidTokenException: Error processing access token. " If the user is logged into Facebook on the same PC, then there isn't an issue. Is there anything that I have to set, or is there some other way I should be performing this connectivity to be able to retrieve the data when the user isn't logged in?
The code I use to get/set the Facebook session is: require 'libraries/facebook/facebook. Php'; // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => 'xxxx', 'secret' => 'xxxx', )); $session = $facebook->getSession(); $me = null; // Session based API call.
If ($session) { //Save to database } catch (FacebookApiException $e) { error_log($e); } } else { $loginUrl = $facebook->getLoginUrl(); header('Location: ' . $loginUrl); } Once I have the session saved to the database from this part, I display the data by posting the database serialized session to this: $session = unserialize($_POST'session'); require_once('libraries/facebook/facebook. Php'); $facebook = new Facebook(array( 'appId' => 'xxxx', 'secret' => 'xxxx', )); $facebook->setSession($session, false); try { $uid = $facebook->getUser(); // Do stuff } catch (FacebookApiException $e) { echo "" .
$e . ""; } Is there anything glaringly wrong with what I'm doing here? Or can I not use this method to create an oAuth connection that lets me request data for users when they are not logged in?
Thanks, Dan php facebook sdk oauth link|improve this question asked Sep 9 '10 at 9:01Dan7512 83% accept rate.
– Martin Bean Sep 9 '10 at 10:04 1 It is a website - however while experimenting around I have changed the type of application be a 'native application', which then provides the option to "stay logged in to xxx" which can be ticked which is what I was looking for! – Dan Sep 9 '10 at 10:44.
By default, the access tokens (OAuth Token) you receive from the Facebook Platform are session-length only. So, what you describe is expected. If you want to continue interacting with the API even after the users have logged out, you will need to request from them the offline_access extended permission, which will then make your access tokens "long lived", which you can store in a database for later use.
Just be aware that if the user modifies the permissions granted to your app, your access token will become invalid (or, at least, incongruent). But you can keep up with permissions changes via Real Time Updates. Note: This does not keep the user "logged in", just gives you the power to act on their behalf when they are not logged in.
I have changed the type of application be a 'native application' instead of 'HTML5/Mobile Web', which then provides the option to "stay logged in to xxx" which can be selected, which didn't seem to be offered by the latter. Have tested it and it appears to now be working, which is good news!
If you need to take user data from API, you can get your application access_token and get your app user data, signed you queries with application access_token. Look at App login section developers.facebook.com/docs/authentication.
Just simply query the API in the following way to get the logout url... $logoutUrl=$facebook->getLogoutUrl(); Use $logoutUrl to log the user out! Thats it!
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.