public function getSession() { $consumerKey = $this->getConsumerKey(); $consumerSecret = $this->getConsumerSecret(); $appId = $this->getAppId(); return YahooSession::requireSession($consumerKey, $consumerSecret, $appId); }
function __construct() { /*取得Yahoo Session*/ $this->yss = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); /*取得登入者的GUID*/ $this->guid = $this->yss->guid; }
<?php // Include the YSP PHP SDK to access the library. // You need to change the path of Yahoo.inc. include_once "lib/Yahoo.inc"; // Define constants to store your Consumer Key and Consumer Secret. define("CONSUMER_KEY", "<your consumer key>"); define("CONSUMER_SECRET", "<your consumer secret>"); // Enable debugging. Errors are reported to Web server's error log. YahooLogger::setDebug(true); // Initializes session and redirects user to Yahoo! to sign in and // then authorize app $yahoo_session = YahooSession::requireSession(CONSUMER_KEY, CONSUMER_SECRET); if ($yahoo_session == NULL) { fatal_error("yahoo_session"); } $data_orig = $yahoo_session->query('select * from social.connections.updates where guid=me'); $updates = $data_orig->query->results->update; $data = $yahoo_session->query('select * from google.translate where q in (select title from social.connections.updates where guid=me) and target="hi"'); foreach ($data->query->results->translatedText as $i => $update) { echo "<div style='height:70px;padding-left:10px;'><div style='float:left;padding:2px;'> <a href='" . $updates[$i]->profile_profileUrl . "'><img style='border:0;' src ='" . $updates[$i]->profile_displayImage . "'> </a></div><div> <a href='" . $updates[$i]->profile_profileUrl . "'>" . $updates[$i]->profile_nickname . "</a> {$update} </div></div>"; }
<?php include_once "lib/Yahoo.inc"; //located at https://github.com/yahoo/yos-social-php //get your keys from https://developer.apps.yahoo.com/dashboard/createKey.html define("API_KEY", "<YOUR_KEY_HERE>"); define("SHARED_SECRET", "<YOUR_SECRET_HERE>"); YahooLogger::setDebug(true); //optional debug output. $session = YahooSession::requireSession(API_KEY, SHARED_SECRET); if ($session == NULL) { echo "<p>Error: Cannot get session object. Check your API Key (Consumer Key) and Shared Secret (Consumer Secret)</p>"; exit; } //find out how many unread messages there are in your ymail.com Inbox $query = 'select folder.unread from ymail.folders where folder.folderInfo.name = "Inbox"'; $queryResponse = $session->query($query); if ($queryResponse == NULL) { echo "<p>Error: No query response. Check your permissions. Also, check the syntax of the YQL query.</p>"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>YQL 3legged OAuth example</title> <script type="text/javascript" charset="utf-8" src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script> <style type="text/css"> #unreadmsg { font-weight:bold; color:#ff0000;
$profile = $user->getProfile(); $name = $profile->nickname; // Getting user name $guid = $profile->guid; // Getting Yahoo ID //Retriving the user $query = mysql_query("SELECT guid,name from yahoo_users where guid = '{$guid}' and oauth_type = 'yahoo'") or die(mysql_error()); $result = mysql_fetch_array($query); if (empty($result)) { // user not present in Database. Store a new user and Create new account for him $query = mysql_query("INSERT INTO yahoo_users(oauth_type, guid, name) VALUES('yahoo', '{$guid}', '{$name}')") or die(mysql_error()); $query = mysql_query("SELECT guid,name from yahoo_users where guid = '{$guid}' and oauth_type = 'yahoo'") or die(mysql_error()); $result = mysql_fetch_array($query); } // Creating session variable for User $_SESSION['login'] = true; $_SESSION['name'] = $result['name']; $_SESSION['guid'] = $result['guid']; $_SESSION['oauth_provider'] = 'yahoo'; } } if (array_key_exists("logout", $_GET)) { // User logging out and Clearing all Session data YahooSession::clearSession(); unset($_SESSION['login']); unset($_SESSION['name']); unset($_SESSION['guid']); unset($_SESSION['oauth_provider']); // After logout Redirection here header("Location: index.php"); }
public function getSession() { return YahooSession::requireSession($this->_getConsumerKey(), $this->_getConsumerSecret(), $this->_getAppId()); }
<?php require 'config.inc'; require YOSDK_PATH; $session_store = new CookieSessionStore(); $session = YahooSession::initSession(KEY, SECRET, APP_ID, TRUE, BASE_URL . '/callback.php', $session_store); $access_token_readable = print_r($session->accessToken, true); //send an update $user = $session->getSessionedUser(); $suid = 'update' . time(); //just a unique string $title = 'this is an update'; $link = 'http://developer.yahoo.com/social/updates/'; $user->insertUpdate($suid, $title, $link); //create a link to the logged-in user's profile page $profile_url = 'http://profiles.yahoo.com/u/' . $user->guid; ?> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <h1>Success!</h1> You have now authorized updates originating from this site to be published on Yahoo! <p/> An event notification has been sent to Yahoo! to demonstrate this behavior. You can see it on <a href="<?php echo $profile_url; ?> " target="_blank">your Yahoo! profile page</a>. <p/> In case you're interested, this is the access token this site can store, refresh, and use to sign requests to the Updates API: <pre> <?php
<?php require_once "../yosdk/Yahoo.inc"; require 'config.inc'; $session = YahooSession::requireSession(KEY, SECRET); $session->accessToken->consumer = KEY; $access_token_filepath = './tokens/' . $session->guid . '_access_token.txt'; file_put_contents($access_token_filepath, json_encode($session->accessToken)); $access_token_readable = print_r($session->accessToken, true); ?> Here is the access token data: <pre> <?php echo $access_token_readable; ?> </pre> It's stored as JSON here:<br/> <?php echo $access_token_filepath; ?>
<?php require_once "../../yosdk/Yahoo.inc"; require_once "CustomSessionStore.inc"; require_once "config.inc"; $redirect = TRUE; $guid = '{guid}'; //set by app logic $sessionStore = new CustomSessionStore($guid); $session = YahooSession::initSession(KEY, SECRET, APPID, $redirect, CALLBACK, $sessionStore); ?> <pre> <?php print_r($session->accessToken); ?> </pre>
public function saveAction() { require 'Yahoo/Yahoo.inc'; $helper = Mage::helper('referralreward'); //YahooLogger::setDebug(true); //YahooLogger::setDebugDestination('LOG'); define('OAUTH_CONSUMER_KEY', $helper->storeConfig('yahoo/key')); define('OAUTH_CONSUMER_SECRET', $helper->storeConfig('yahoo/secret')); define('OAUTH_DOMAIN', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)); define('OAUTH_APP_ID', $helper->storeConfig('yahoo/appid')); $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($hasSession == FALSE) { $callback = YahooUtil::current_url() . "?in_popup"; $sessionStore = new NativeSessionStore(); $authUrl = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore); header("Location: " . $authUrl); exit; } else { $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($session) { $user = $session->getSessionedUser(); //$profile = $user->getProfile(); $contacts = $user->getContactSync(); if ($contacts) { $contacts = $this->XmltoArray($contacts); $names = array(); $emails = array(); foreach ($contacts['contactsync']['contacts'] as $key => $profileContact) { foreach ($profileContact['fields'] as $contact) { $emails[] = $contact['value']; $names[] = ''; } } YahooSession::clearSession(); $customer_id = (int) $this->_getSession()->getId(); $count = Mage::getModel('referralreward/friends')->saveFriends($customer_id, $emails, $names); if ($count['enable']) { if ($count['enable'] > 1) { $this->_getSession()->addSuccess($this->__('%s have been added', $count['enable'])); } else { $this->_getSession()->addSuccess($this->__('%s has been added', $count['enable'])); } } if ($count['disable']) { $this->_getSession()->addSuccess($this->__('%s already registered', $count['disable'])); } if ($count['enable'] == 0 && $count['disable'] == 0) { $this->_getSession()->addError($this->__("no emails were added")); } } else { $this->_getSession()->addError($this->__("no emails were added")); } } echo "<script>\n window.opener.location.reload(true);\n window.close();\n </script>"; } }
/** * @private */ function accessTokenExpired($accessToken, $consumer, $applicationId, $sessionStore) { global $GLOBAL_YAHOO_SESSION; $now = time(); if(($accessToken->handleExpires === -1) || ($now < $accessToken->handleExpires)) { // Either the access session handle doesn't expire // or it hasn't expired yet. Get a new access token. $newAccessToken = YahooAuthorization::getAccessToken( $consumer->key, $consumer->secret, $accessToken, null); if(is_null($newAccessToken)) { YahooLogger::error("Failed to fetch access token"); $GLOBAL_YAHOO_SESSION = NULL; } $sessionStore->storeAccessToken($newAccessToken); YahooLogger::debug("Got new AT/ATS from ASH!"); YahooLogger::debug("OAuth AT: " . $newAccessToken->key . " ATS: ". $newAccessToken->secret); $GLOBAL_YAHOO_SESSION = new YahooSession( $consumer, $newAccessToken, $applicationId); } else { // The access token is expired and we don't have // a sufficient access session handle to renew // the access token. Clear the cookie and redirect // to authorization point or return a NULL session. $sessionStore->clearAccessToken(); if ($redirect) { YahooSession::redirectForAuthorization($consumer->key, $consumer->secret, $callback, $sessionStore); } else { $GLOBAL_YAHOO_SESSION = NULL; } } }
# do not show notices as library is php4 compatable ini_set('display_errors', true); YahooLogger::setDebug(true); YahooLogger::setDebugDestination('LOG'); // use memcache to store oauth credentials via php native sessions ini_set('session.save_handler', 'memcache'); session_save_path('tcp://localhost:11211?persistent=1&weight=1&timeout=1&retry_interval=15'); session_start(); // Make sure you obtain application keys before continuing by visiting: // https://developer.yahoo.com/dashboard/createKey.html // create a Yahoo! Open Application - http://developer.yahoo.com/dashboard $consumerKey = 'dj0yJmk9WUxPUkhFUWxISWpvJmQ9WVdrOWFYWmhTVzVDTXpBbWNHbzlNVGt4TmpJNU1EazROdy0tJnM9Y29uc3VtZXJzZWNyZXQmeD01Ng--'; $consumerKeySecret = 'f893cf549be5cb37f83b1414e2ff212df2ea4c18'; $applicationId = 'ivaInB30'; // oauth dance if not authenticated $session = YahooSession::requireSession($consumerKey, $consumerKeySecret, $applicationId); // get oauthed user guid + profile $user = $session->getSessionedUser(); $header = '<h2><img src="http://delicious.com/favicon.ico" title="Delicious" width="16" height="16" />Delicious // social bookmarking</h2>'; $content = '<div id="bookmarks">'; // if user is logged in and oauth is valid if (is_object($user)) { // load y! profile data $profile = $user->getProfile(); // get yap app instance for yql / small view $application = new YahooApplication($consumerKey, $consumerKeySecret); // delicious yql $yql = "use 'http://www.javarants.com/delicious/delicious.feeds.xml' as delicious.feeds;"; $yql .= "select * from delicious.feeds"; if (isset($_REQUEST['username'])) { // validate delicious user and set username in datastore
function ShareYahoo($text, $userID, $linktext, $linkurl) { App::import('Vendor', 'Yahoo', array('file' => 'yahoo/Yahoo.inc')); $Setting = ClassRegistry::Init("Setting"); $settings = $Setting->find('first'); $settings = $settings['Setting']; $hasSession = YahooSession::hasSession($settings['yahoo_consumer_key'], $settings['yahoo_consumer_secret'], $settings['yahoo_app_id']); if ($hasSession != FALSE) { $session = YahooSession::requireSession($settings['yahoo_consumer_key'], $settings['yahoo_consumer_secret'], $settings['yahoo_app_id']); $user = $session->getSessionedUser(); // create an unique hash of the update data using md5 $suid = md5($text . $linktext . $linkurl . time()); // insert the update... $user->insertUpdate($suid, $text, $linkurl, $linktext); return true; } return false; }
YahooSession::clearSession(); header("Location: sampleapp.php"); } // check for the existance of a session. // this will determine if we need to show a pop-up and fetch the auth url, // or fetch the user's social data. $hasSession = YahooSession::hasSession(CONSUMER_KEY, CONSUMER_SECRET, APP_ID); if ($hasSession == FALSE) { // create the callback url, $callback = YahooUtil::current_url() . "?in_popup"; // pass the credentials to get an auth url. // this URL will be used for the pop-up. $auth_url = YahooSession::createAuthorizationUrl(CONSUMER_KEY, CONSUMER_SECRET, $callback); } else { // pass the credentials to initiate a session $session = YahooSession::requireSession(CONSUMER_KEY, CONSUMER_SECRET, APP_ID); // if the in_popup flag is detected, // the pop-up has loaded the callback_url and we can close this window. if (array_key_exists("in_popup", $_GET)) { close_popup(); exit; } // if a session is initialized, fetch the user's profile information if ($session) { // Get the currently sessioned user. $user = $session->getSessionedUser(); // Load the profile for the current user. $profile = $user->getProfile(); } } /**
require_once '../../key.php'; require_once '../server.php'; // Include the YOS library. require 'lib/Yahoo.inc.php'; // Place Your App ID here if (array_key_exists("logout", $_GET)) { YahooSession::clearSession(); unset($_SESSION['login']); header("Location: index.php"); } else { $session = YahooSession::requireSession(YAHOO_CONSUMER_KEY, YAHOO_CONSUMER_SECRET, YAHOO_APP_ID); if (is_object($session)) { $user = $session -> getSessionedUser(); $friend = $user -> getContacts(0, 5000); $aContactList = array(); if ($friend -> contacts -> count > 0) { foreach ($friend->contacts->contact as $oContact) { $sEmail = $sUsername = ''; foreach ($oContact->fields as $aField) { switch($aField->type) { case 'yahooid' :
<?php /* Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license */ require_once "config.php"; require_once "php_sdk/Yahoo.inc"; require_once "CustomSessionStore.inc"; //capture POST data for update $title = $_POST['title']; $description = $_POST['description']; $link = $_POST['link']; $token = $_POST['token']; //initialize session $sessionStore = new CustomSessionStore(); $session = YahooSession::initSession(KEY, SECRET, APPID, TRUE, CALLBACK, $sessionStore); $yahoo_user = $session->getSessionedUser(); //create new update if ($title) { $suid = $yahoo_user->guid . time(); if ($yahoo_user->insertUpdate($suid, $title, $link, $description)) { echo "Update Successful"; } }
YahooSession::clearSession(); header("Location: sampleapp.php"); } // check for the existance of a session. // this will determine if we need to show a pop-up and fetch the auth url, // or fetch the user's social data. $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($hasSession == FALSE) { // create the callback url, $callback = YahooUtil::current_url() . "?in_popup"; // pass the credentials to get an auth url. // this URL will be used for the pop-up. $auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback); } else { // pass the credentials to initiate a session $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); // if the in_popup flag is detected, // the pop-up has loaded the callback_url and we can close this window. if (array_key_exists("in_popup", $_GET)) { close_popup(); exit; } // if a session is initialized, fetch the user's profile information if ($session) { // Get the currently sessioned user. $user = $session->getSessionedUser(); // Load the profile for the current user. $profile = $user->getProfile(); } } /**
<?php error_reporting(E_ALL); require_once "config.php"; require_once "{path to PHP SDK}/lib/Yahoo.inc"; require_once "CustomSessionStore.inc"; $store = new CustomSessionStore(array('third_party_callback' => isset($_GET['third_party_callback']) ? urldecode($_GET['third_party_callback']) : NULL, 'oauth_token' => isset($_GET['oauth_token']) ? urldecode($_GET['oauth_token']) : NULL)); $verifier = isset($_GET['oauth_verifier']) ? $_GET['oauth_verifier'] : NULL; $session = YahooSession::requireSession(KEY, SECRET, APPID, CALLBACK, $store, $verifier); if ($session && $session->guid) { header(sprintf('Location: %s?status=success&guid=%s', $session->accessToken->third_party_callback, $session->accessToken->guid)); } else { header(sprintf('Location: %s?status=error', $session->accessToken->third_party_callback)); }
/** * @Yahoo login action * * Connect Yahoo Using oAuth coonection. * * @return string URL eiether customer save and loggedin or an error if any occurs */ public function yahoopostAction() { /** * Include @Yahoo library files for oAuth connection */ require 'sociallogin/lib/Yahoo.inc'; YahooLogger::setDebug(true); YahooLogger::setDebugDestination('LOG'); /** * * @param string $yahoo_client_id, * $yahoo_client_secret and $yahoo_developer_key * * Using this params setting up the connection to yahoo */ $yahooClientId = Mage::getStoreConfig('sociallogin/yahoo/yahoo_id'); $yahooClientSecret = Mage::getStoreConfig('sociallogin/yahoo/yahoo_secret'); $yahooDeveloperKey = Mage::getStoreConfig('sociallogin/yahoo/yahoo_develop'); $yahooDomain = Mage::getUrl(); /** * Use memcache to store oauth credentials via php native sessions * * Make sure you obtain application keys before continuing by visiting:<https://developer.yahoo.com/dashboard/createKey.html> */ define('OAUTH_CONSUMER_KEY', "{$yahooClientId}"); define('OAUTH_CONSUMER_SECRET', "{$yahooClientSecret}"); define('OAUTH_DOMAIN', "{$yahooDomain}"); define('OAUTH_APP_ID', "{$yahooDeveloperKey}"); $para = $this->getRequest()->getParams(); $data = $this->getRequest()->getParam('fb'); if (array_key_exists("logout", $para)) { YahooSession::clearSession(); $url = "index.php"; $this->_redirectUrl($url); } $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); YahooUtil::current_url(); if (!$hasSession) { $callback = YahooUtil::current_url() . "?in_popup"; $sessionStore = new NativeSessionStore(); $authUrl = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore); if ($authUrl) { $this->_redirectUrl($authUrl); } } else { $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($session) { $user = $session->getSessionedUser(); $profile = $user->getProfile(); $profile->guid; $email = $profile->emails[0]->handle; $firstName = $profile->givenName; $lastName = $profile->familyName; if ($email == '') { Mage::getSingleton('customer/session')->addError($this->__('Yahoo Login connection failed')); $url = Mage::helper('customer')->getAccountUrl(); return $this->_redirectUrl($url); } else { $this->customerAction($firstName, $lastName, $email, 'Yahoo', $data); } } } }
<?php require 'config.inc'; require_once "yosdk/Yahoo.inc"; require_once "CustomSessionStore.inc"; $applicationId = ''; $redirect = TRUE; $callback = ''; $guid = '{guid}'; //app logic would provide this $sessionStore = new CustomSessionStore($guid); $session = YahooSession::initSession(KEY, SECRET, $applicationId, $redirect, $callback, $sessionStore); $user = $session->getSessionedUser(); $start = 0; $count = 10; $total = 10; var_dump($user->getConnections($start, $count, $total));
$storedSessionId = json_decode($response->value); if ($passedSessionId != $storedSessionId) { $data = array('status' => 'error', 'details' => 'invalid session id: ' . json_decode($response->value)); break; } //END: validate request using session id //settings $oauthIncludePath = '../../yosdk/'; $includePath = get_include_path() . PATH_SEPARATOR . $oauthIncludePath; set_include_path($includePath); require_once 'Yahoo.inc'; require_once 'YahooSessionStore.inc'; require_once 'CustomSessionStore.php'; // session store interface defined in Yahoo! SDK $yahooSdkSessionStore = new CustomSessionStore($storage, $storageKey); $yahooSession = YahooSession::requireSession($value->consumerKey, $value->consumerSecret, '71bgIV7k', null, $yahooSdkSessionStore); $url = urldecode($input['url']); parse_str(urldecode($input['params']), $params); $response = $yahooSession->client->get($url, $params); $data = array('response' => json_decode($response['responseBody']), 'debug' => $validId); break; default: //error: invalid service id break; } //format data for output $json = urlencode(json_encode($data)); $size = 100; $chunks = str_split($json, $size); $total = count($chunks); //output markup