[twitter-dev] Re: Check if user is already logged in?
Thanks. But I know how to do that. I mean when the user returns to the site, generally just like a remember me cookie. The Facebook API checks for a current Facebook session so long as the user has activated the app, so it behaves like a cookie by automatically logging the user in. My custom user system also does this. So I wanted to know if I could do this with Twitter as well so that all three user systems behaved the same way. On Nov 19, 11:59 pm, Abraham Williams 4bra...@gmail.com wrote: With TwitterOAuth you have to maintain your own sessions. When you get a users access token save that into $_SESSION or save something like $_SESSION['twitter_users_auth'] = TRUE. Check if that is set and if it is not you know the user is not currently logged into your site with Twitter. Abraham - Abraham Williams | Hacker Advocate | abrah.am @abraham https://twitter.com/abraham | github.com/abraham | blog.abrah.am This email is: [ ] shareable [x] ask first [ ] private. On Fri, Nov 19, 2010 at 18:36, Patrick Golden artiz...@gmail.com wrote: Is it possible to check to see if a user is logged in to Twitter and has authorized the application without having any redirects? For first time login, I have this basic code: ? require(twitter/twitteroauth.php); session_start(); // The TwitterOAuth instance $twitteroauth = new TwitterOAuth('xxx', 'xxx'); // Requesting authentication tokens, the parameter is the URL we will be redirected to $request_token = $twitteroauth-getRequestToken('xxx'); // Saving them into the session $_SESSION['twitter_token'] = $request_token['oauth_token']; $_SESSION['twitter_secret'] = $request_token['oauth_token_secret']; // If everything goes well.. if($twitteroauth-http_code==200){ // Let's generate the URL and redirect $url = $twitteroauth- getAuthorizeURL($request_token['oauth_token']); header('Location: '. $url); } ? That's on a separate page, something like twitter-login.php, so I only want to use that when the user isn't logged in (i.e. the user clicks a login with Twitter link). I have a function for my site's user system that displays either a login form (if not logged in; has Facebook/Twitter buttons) or a user control panel (if logged in). The function prototype is something like: displayLogin(bool $facebook, bool $twitter, string $username) where the first two parameters indicate if the user is signed in with Facebook, Twitter, or neither. With Facebook, I can check with the API if the user has a session on Facebook and has verified the application by: $session = $facebook-getSession(); $me = null; // Session based API call. if ($session) { try { $uid = $facebook-getUser(); $me = $facebook-api('/me'); } catch (FacebookApiException $e) { error_log($e); } } else { $me = false; } if ($me) { // do stuff because the user is logged in and has authorized the app in the past } And so if $me isn't false, I know the user is logged in and I can set session variables, and pass a boolean true to the displayLogin() function for Facebook. All of this is processed on my index page, hence no redirects. Is there any way to do this with Twitter without having to do the redirect? Would I have to use javascript or something? My PHP library is the twitteroauth library. Thank you! -- Twitter developer documentation and resources:http://dev.twitter.com/doc API updates via Twitter:http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk -- Twitter developer documentation and resources: http://dev.twitter.com/doc API updates via Twitter: http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk
[twitter-dev] Re: Check if user is already logged in?
Actually, I /could/ just use a cookie for that, right? Just set a special Twitter cookie and when the user returns, redirect them to the auth/login page if they don't have a session set but do have the cookie set. I think that would work. It's not as seamless as Facebook but oh well. =P On Nov 20, 8:39 am, Patrick Golden artiz...@gmail.com wrote: Thanks. But I know how to do that. I mean when the user returns to the site, generally just like a remember me cookie. The Facebook API checks for a current Facebook session so long as the user has activated the app, so it behaves like a cookie by automatically logging the user in. My custom user system also does this. So I wanted to know if I could do this with Twitter as well so that all three user systems behaved the same way. On Nov 19, 11:59 pm, Abraham Williams 4bra...@gmail.com wrote: With TwitterOAuth you have to maintain your own sessions. When you get a users access token save that into $_SESSION or save something like $_SESSION['twitter_users_auth'] = TRUE. Check if that is set and if it is not you know the user is not currently logged into your site with Twitter. Abraham - Abraham Williams | Hacker Advocate | abrah.am @abraham https://twitter.com/abraham | github.com/abraham | blog.abrah.am This email is: [ ] shareable [x] ask first [ ] private. On Fri, Nov 19, 2010 at 18:36, Patrick Golden artiz...@gmail.com wrote: Is it possible to check to see if a user is logged in to Twitter and has authorized the application without having any redirects? For first time login, I have this basic code: ? require(twitter/twitteroauth.php); session_start(); // The TwitterOAuth instance $twitteroauth = new TwitterOAuth('xxx', 'xxx'); // Requesting authentication tokens, the parameter is the URL we will be redirected to $request_token = $twitteroauth-getRequestToken('xxx'); // Saving them into the session $_SESSION['twitter_token'] = $request_token['oauth_token']; $_SESSION['twitter_secret'] = $request_token['oauth_token_secret']; // If everything goes well.. if($twitteroauth-http_code==200){ // Let's generate the URL and redirect $url = $twitteroauth- getAuthorizeURL($request_token['oauth_token']); header('Location: '. $url); } ? That's on a separate page, something like twitter-login.php, so I only want to use that when the user isn't logged in (i.e. the user clicks a login with Twitter link). I have a function for my site's user system that displays either a login form (if not logged in; has Facebook/Twitter buttons) or a user control panel (if logged in). The function prototype is something like: displayLogin(bool $facebook, bool $twitter, string $username) where the first two parameters indicate if the user is signed in with Facebook, Twitter, or neither. With Facebook, I can check with the API if the user has a session on Facebook and has verified the application by: $session = $facebook-getSession(); $me = null; // Session based API call. if ($session) { try { $uid = $facebook-getUser(); $me = $facebook-api('/me'); } catch (FacebookApiException $e) { error_log($e); } } else { $me = false; } if ($me) { // do stuff because the user is logged in and has authorized the app in the past } And so if $me isn't false, I know the user is logged in and I can set session variables, and pass a boolean true to the displayLogin() function for Facebook. All of this is processed on my index page, hence no redirects. Is there any way to do this with Twitter without having to do the redirect? Would I have to use javascript or something? My PHP library is the twitteroauth library. Thank you! -- Twitter developer documentation and resources:http://dev.twitter.com/doc API updates via Twitter:http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk -- Twitter developer documentation and resources: http://dev.twitter.com/doc API updates via Twitter: http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk
[twitter-dev] Re: Check if user is already logged in?
This works. =] On Nov 20, 9:53 am, Patrick Golden artiz...@gmail.com wrote: Actually, I /could/ just use a cookie for that, right? Just set a special Twitter cookie and when the user returns, redirect them to the auth/login page if they don't have a session set but do have the cookie set. I think that would work. It's not as seamless as Facebook but oh well. =P On Nov 20, 8:39 am, Patrick Golden artiz...@gmail.com wrote: Thanks. But I know how to do that. I mean when the user returns to the site, generally just like a remember me cookie. The Facebook API checks for a current Facebook session so long as the user has activated the app, so it behaves like a cookie by automatically logging the user in. My custom user system also does this. So I wanted to know if I could do this with Twitter as well so that all three user systems behaved the same way. On Nov 19, 11:59 pm, Abraham Williams 4bra...@gmail.com wrote: With TwitterOAuth you have to maintain your own sessions. When you get a users access token save that into $_SESSION or save something like $_SESSION['twitter_users_auth'] = TRUE. Check if that is set and if it is not you know the user is not currently logged into your site with Twitter. Abraham - Abraham Williams | Hacker Advocate | abrah.am @abraham https://twitter.com/abraham | github.com/abraham | blog.abrah.am This email is: [ ] shareable [x] ask first [ ] private. On Fri, Nov 19, 2010 at 18:36, Patrick Golden artiz...@gmail.com wrote: Is it possible to check to see if a user is logged in to Twitter and has authorized the application without having any redirects? For first time login, I have this basic code: ? require(twitter/twitteroauth.php); session_start(); // The TwitterOAuth instance $twitteroauth = new TwitterOAuth('xxx', 'xxx'); // Requesting authentication tokens, the parameter is the URL we will be redirected to $request_token = $twitteroauth-getRequestToken('xxx'); // Saving them into the session $_SESSION['twitter_token'] = $request_token['oauth_token']; $_SESSION['twitter_secret'] = $request_token['oauth_token_secret']; // If everything goes well.. if($twitteroauth-http_code==200){ // Let's generate the URL and redirect $url = $twitteroauth- getAuthorizeURL($request_token['oauth_token']); header('Location: '. $url); } ? That's on a separate page, something like twitter-login.php, so I only want to use that when the user isn't logged in (i.e. the user clicks a login with Twitter link). I have a function for my site's user system that displays either a login form (if not logged in; has Facebook/Twitter buttons) or a user control panel (if logged in). The function prototype is something like: displayLogin(bool $facebook, bool $twitter, string $username) where the first two parameters indicate if the user is signed in with Facebook, Twitter, or neither. With Facebook, I can check with the API if the user has a session on Facebook and has verified the application by: $session = $facebook-getSession(); $me = null; // Session based API call. if ($session) { try { $uid = $facebook-getUser(); $me = $facebook-api('/me'); } catch (FacebookApiException $e) { error_log($e); } } else { $me = false; } if ($me) { // do stuff because the user is logged in and has authorized the app in the past } And so if $me isn't false, I know the user is logged in and I can set session variables, and pass a boolean true to the displayLogin() function for Facebook. All of this is processed on my index page, hence no redirects. Is there any way to do this with Twitter without having to do the redirect? Would I have to use javascript or something? My PHP library is the twitteroauth library. Thank you! -- Twitter developer documentation and resources:http://dev.twitter.com/doc API updates via Twitter:http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk -- Twitter developer documentation and resources: http://dev.twitter.com/doc API updates via Twitter: http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk