php - can anyone tell why $auth_url is going blank in this code? -
my code given below: i'm trying use code import yahoo contacts in i've given app_id, callback url, customer id , customer secret. don't understand why link creating pop ups same url. may due $auth_url, can i'm missing? file).'/lib/yahoo.inc';
//for converting xml array function xmltoarray($xml) { $array = json_decode(json_encode($xml), true); foreach ( array_slice($array, 0) $key => $value ) { if ( empty($value) ) $array[$key] = null; elseif ( is_array($value) ) $array[$key] = xmltoarray($value); } return $array; } // debug settings //error_reporting(e_all | e_notice); # not show notices library php4 compatable //ini_set('display_errors', true); yahoologger::setdebug(true); yahoologger::setdebugdestination('log'); // use memcache store oauth credentials via php native sessions //ini_set('session.save_handler', 'files'); //session_save_path('/tmp/'); session_start(); // make sure obtain application keys before continuing visiting: // https://developer.yahoo.com/dashboard/createkey.html define('oauth_consumer_key', '****'); define('oauth_consumer_secret', '****'); define('oauth_domain', '*****'); define('oauth_app_id', '****'); if(array_key_exists("logout", $_get)) { // if session exists , logout flag detected // clear session tokens , reload page. yahoosession::clearsession(); header("location: index.php"); } // check existance of session. // determine if need show pop-up , fetch auth url, // or fetch user's social data. $hassession = yahoosession::hassession(oauth_consumer_key, oauth_consumer_secret, oauth_app_id); if($hassession == false) { // create callback url, $callback = yahooutil::current_url()."?in_popup"; $sessionstore = new nativesessionstore(); // pass credentials auth url. // url used pop-up. $auth_url = yahoosession::createauthorizationurl(oauth_consumer_key, oauth_consumer_secret, $callback, $sessionstore); } else { // pass credentials initiate session $session = yahoosession::requiresession(oauth_consumer_key, oauth_consumer_secret, oauth_app_id); // if in_popup flag detected, // pop-up has loaded callback_url , can close window. if(array_key_exists("in_popup", $_get)) { close_popup(); exit; } // if session initialized, fetch user's profile information if($session) { // sessioned user. $user = $session->getsessioneduser(); // load profile current user. $profile = $user->getprofile(); $profile_contacts=xmltoarray($user->getcontactsync()); $contacts=array(); foreach($profile_contacts['contactsync']['contacts'] $key=>$profilecontact){ foreach($profilecontact['fields'] $contact){ $contacts[$key][$contact['type']]=$contact['value']; } } // echo "<pre/>"; // print_r($contacts);exit; } } //echo "<pre />"; //print_r($_session);exit; /** * helper method close pop-up window via javascript. */ function close_popup() { ?> <script type="text/javascript"> window.close(); </script> <?php } ?> <!doctype html public "-//w3c//dtd html 4.01//en"> <html> <head> <title>get contact list yahoo-idiot minds</title> <style type="text/css"> body{ background-color: #f2f2f2; } .yh_frnds{ list-style:none; } .yh_frnds li{ padding:10px; float:left; width:30%; } .frnd_list{ margin-top:-25px; margin-left:40px; } .fb_frnds a{ text-decoration:none; background: #333; filter: progid:dximagetransform.microsoft.gradient(startcolorstr='#333', endcolorstr='#d95858'); /* ie */ background: -webkit-gradient(linear, left top, left bottom, from(#333), to(#d95858)); /* webkit browsers */ background: -moz-linear-gradient(top, #333, #d95858)/* firefox 3.6+ */ ; color: #ffffff; float: right; font: bold 13px arial; margin-right:110px ; } </style> <!-- combo-handled yui js files: --> <script type="text/javascript" src="yahoo-dom-event.js"></script> <script type="text/javascript" src="popupmanager.js"></script> </head> <body> <?php if($hassession == false) { // if session not exist, output // login / share button linked auth_url. ?> <a href="<?php echo $auth_url; ?>" id="yloginlink"><img src="yahoo-oauth-connect.png" style="width:150px;margin-left: 350px;" title="get contact list yahoo-idiot minds" alt="get contact list yahoo-idiot minds" /></a> <?php } else if($hassession && $profile) { // if session exist , profile data // fetched without error, print out simple usercard. ?> <img src="<?php echo $profile->image->imageurl; ?>" style="width:10%;" /> <h2>hi <a href="<?php echo $profile->profileurl; ?>" target="_blank"><?php echo $profile->nickname; ?></a> </h2> <?php if($profile->status->message != "") { $statusdate = date('f j, y, g:i a', strtotime($profile->status->laststatusmodified)); echo sprintf("<p><strong>“</strong>%s<strong>”</strong> on %s</p>", $profile->status->message, $statusdate); } echo "<p><a href=\"?logout\">logout</a></p>"; ?> <ul class="yh_frnds"> <?php foreach($contacts $user_friend){ if(isset($user_friend['email'])){ ?> <li ><img src="yahoo1.png" width="30" height="30"/> <div class="frnd_list"><strong><?php echo $user_friend['name']['givenname']; ?></strong><br /><?php echo $user_friend['email'];?></div> </li> <?php } } ?> </ul> <?php } ?> <script type="text/javascript"> var event = yahoo.util.event; var _gel = function(el) {return document.getelementbyid(el)}; function handledomready() { if(_gel("yloginlink")) { event.addlistener("yloginlink", "click", handleloginclick); } } function handleloginclick(event) { // block url opening normal event.preventdefault(event); // open pop-up using auth_url var auth_url = _gel("yloginlink").href; popupmanager.open(auth_url,600,435); } event.ondomready(handledomready); </script> </body> </html>
you never changed "hassession" needle. imagine: check, if user has active session. if have no active session, auth using same service. after login - never re-check session / or update "hassession" needle. use following code:
( search @tyralcori finding changes)
//for converting xml array function xmltoarray($xml) { $array = json_decode(json_encode($xml), true); foreach ( array_slice($array, 0) $key => $value ) { if ( empty($value) ) $array[$key] = null; elseif ( is_array($value) ) $array[$key] = xmltoarray($value); } return $array; } // debug settings //error_reporting(e_all | e_notice); # not show notices library php4 compatable //ini_set('display_errors', true); yahoologger::setdebug(true); yahoologger::setdebugdestination('log'); // use memcache store oauth credentials via php native sessions //ini_set('session.save_handler', 'files'); //session_save_path('/tmp/'); session_start(); // make sure obtain application keys before continuing visiting: // https://developer.yahoo.com/dashboard/createkey.html define('oauth_consumer_key', '****'); define('oauth_consumer_secret', '****'); define('oauth_domain', '*****'); define('oauth_app_id', '****'); if(array_key_exists("logout", $_get)) { // if session exists , logout flag detected // clear session tokens , reload page. yahoosession::clearsession(); header("location: index.php"); } // check existance of session. // determine if need show pop-up , fetch auth url, // or fetch user's social data. $hassession = yahoosession::hassession(oauth_consumer_key, oauth_consumer_secret, oauth_app_id); if($hassession == false) { // create callback url, $callback = yahooutil::current_url()."?in_popup"; $sessionstore = new nativesessionstore(); // pass credentials auth url. // url used pop-up. $auth_url = yahoosession::createauthorizationurl(oauth_consumer_key, oauth_consumer_secret, $callback, $sessionstore); // @tyralcori changes: re-check session after authorization $hassession = yahoosession::hassession(oauth_consumer_key, oauth_consumer_secret, oauth_app_id); } else { // pass credentials initiate session $session = yahoosession::requiresession(oauth_consumer_key, oauth_consumer_secret, oauth_app_id); // if in_popup flag detected, // pop-up has loaded callback_url , can close window. if(array_key_exists("in_popup", $_get)) { close_popup(); exit; } // if session initialized, fetch user's profile information if($session) { // sessioned user. $user = $session->getsessioneduser(); // load profile current user. $profile = $user->getprofile(); $profile_contacts=xmltoarray($user->getcontactsync()); $contacts=array(); foreach($profile_contacts['contactsync']['contacts'] $key=>$profilecontact){ foreach($profilecontact['fields'] $contact){ $contacts[$key][$contact['type']]=$contact['value']; } } // echo "<pre/>"; // print_r($contacts);exit; } } //echo "<pre />"; //print_r($_session);exit; /** * helper method close pop-up window via javascript. */ function close_popup() { ?> <script type="text/javascript"> window.close(); </script> <?php } ?> <!doctype html public "-//w3c//dtd html 4.01//en"> <html> <head> <title>get contact list yahoo-idiot minds</title> <style type="text/css"> body{ background-color: #f2f2f2; } .yh_frnds{ list-style:none; } .yh_frnds li{ padding:10px; float:left; width:30%; } .frnd_list{ margin-top:-25px; margin-left:40px; } .fb_frnds a{ text-decoration:none; background: #333; filter: progid:dximagetransform.microsoft.gradient(startcolorstr='#333', endcolorstr='#d95858'); /* ie */ background: -webkit-gradient(linear, left top, left bottom, from(#333), to(#d95858)); /* webkit browsers */ background: -moz-linear-gradient(top, #333, #d95858)/* firefox 3.6+ */ ; color: #ffffff; float: right; font: bold 13px arial; margin-right:110px ; } </style> <!-- combo-handled yui js files: --> <script type="text/javascript" src="yahoo-dom-event.js"></script> <script type="text/javascript" src="popupmanager.js"></script> </head> <body> <?php if($hassession == false) { // if session not exist, output // login / share button linked auth_url. ?> <a href="<?php echo $auth_url; ?>" id="yloginlink"><img src="yahoo-oauth-connect.png" style="width:150px;margin-left: 350px;" title="get contact list yahoo-idiot minds" alt="get contact list yahoo-idiot minds" /></a> <?php } else if($hassession && $profile) { // if session exist , profile data // fetched without error, print out simple usercard. ?> <img src="<?php echo $profile->image->imageurl; ?>" style="width:10%;" /> <h2>hi <a href="<?php echo $profile->profileurl; ?>" target="_blank"><?php echo $profile->nickname; ?></a> </h2> <?php if($profile->status->message != "") { $statusdate = date('f j, y, g:i a', strtotime($profile->status->laststatusmodified)); echo sprintf("<p><strong>“</strong>%s<strong>”</strong> on %s</p>", $profile->status->message, $statusdate); } echo "<p><a href=\"?logout\">logout</a></p>"; ?> <ul class="yh_frnds"> <?php foreach($contacts $user_friend){ if(isset($user_friend['email'])){ ?> <li ><img src="yahoo1.png" width="30" height="30"/> <div class="frnd_list"><strong><?php echo $user_friend['name']['givenname']; ?></strong><br /><?php echo $user_friend['email'];?></div> </li> <?php } } ?> </ul> <?php } ?> <script type="text/javascript"> var event = yahoo.util.event; var _gel = function(el) {return document.getelementbyid(el)}; function handledomready() { if(_gel("yloginlink")) { event.addlistener("yloginlink", "click", handleloginclick); } } function handleloginclick(event) { // block url opening normal event.preventdefault(event); // open pop-up using auth_url var auth_url = _gel("yloginlink").href; popupmanager.open(auth_url,600,435); } event.ondomready(handledomready); </script> </body> </html>
Comments
Post a Comment