capson Posted February 9, 2014 Share Posted February 9, 2014 (edited) Hello, I am very new to php, I have some ability with vba but of no help with this project. I am trying to help a small nonprofit with a Linkedin project. I found this code here it does a part of what I need, it collects the authentication token from the first user that gives permission to do so. The problem is it only collects the first user authentication token and I need it to collect all users authentication tokens. Thanks for any help <?php /** * This is just for illustrative purposes. Ideally should be a user object and based on a real database */ class TokenDB { static $file = 'token.storage'; public static function getToken(){ return @file_get_contents(TokenDB::$file); } public static function setToken($t){ file_put_contents(TokenDB::$file,$t); } public static function resetToken(){ file_put_contents(TokenDB::$file,''); } } include '../simplelinkedin.class.php'; //Set up the API $ln = new SimpleLinkedIn('xxxx', 'yyyy'); //Set the current consumer token as the one stored in our DB. $ln->setTokenData(TokenDB::getToken()); if($ln->authorize()){ try { //Do some OAuth requests... $user = $ln->fetch('GET', '/v1/people/~:(firstName,lastName)'); print "Hello $user->firstName $user->lastName."; //Update stored token. $tokenData = $ln->getTokenData(); TokenDB::setToken($tokenData['access_token']); } catch(SimpleLinkedInException $e){ //If token was expired or invalid, we reset and reauthorize. if($e->getLastResponse()->status == 401){ //reset the stored token, so we can go through the authorization process //again at page refresh TokenDB::resetToken(); //Reauthorize.. $ln->authorize(); exit; } else throw $e; } } ?> Edited February 9, 2014 by capson Quote Link to comment https://forums.phpfreaks.com/topic/286066-alter-code-to-collect-all-authentication-tokens/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.