static function test15() { require '../OauthPanda.class.php'; $foo = new OauthPanda(array('exception_handling' => 'throw', 'request_client' => new YahooCurlWrapper('../YahooCurl.class.php'), 'oauth_client' => new StandardOauthWrapper('../OAuth.php'), 'consumer_key' => YAHOO_OAUTH_CONSUMER_KEY, 'consumer_secret' => YAHOO_OAUTH_CONSUMER_SECRET)); try { $response = $foo->GET(array('url' => 'https://api.login.yahoo.com/oauth/v2/get_request_token', 'params' => array('oauth_callback' => OAUTH_CALLBACK_URL))); //we should get a request token back TestUtils::assertTrue(false !== strpos($response['response_body'], 'oauth_token=')); } catch (Exception $e) { //no exception should be thrown TestUtils::assertTrue(false, '' . print_r($e, true)); } }
//exchange request token for access token $response = $foo->set(array('oauth_params_location' => 'post', 'token' => $request_token))->POST(array('url' => 'https://api.login.yahoo.com/oauth/v2/get_token', 'params' => array('oauth_verifier' => $_GET['oauth_verifier']))); parse_str($response['response_body'], $access_token_data); //sanity check assert(isset($access_token_data['oauth_token'])); //format access token obj as expected by std oauth lib $access_token = buildAccessTokenObject($access_token_data['oauth_token'], $access_token_data['oauth_token_secret'], $access_token_data['xoauth_yahoo_guid'], $access_token_data['oauth_session_handle'], $access_token_data['oauth_expires_in'], $access_token_data['oauth_authorization_expires_in']); //store token for future usage file_put_contents('access_token.txt', serialize($access_token)); //fetch data using token $url = "http://social.yahooapis.com/v1/users.guid({$access_token->guid})/profile"; $params = array('format' => 'json'); $response = $foo->set(array('oauth_params_location' => 'header', 'token' => $access_token))->GET(array('url' => $url, 'params' => $params)); $response_body = json_decode($response['response_body']); //do something w/ data ... var_dump($response_body); } else { //get request token $response = $foo->GET(array('url' => 'https://api.login.yahoo.com/oauth/v2/get_request_token', 'params' => array('oauth_callback' => OAUTH_CALLBACK_URL))); //extract token parse_str($response['response_body'], $request_token_response); //sanity check assert(isset($request_token_response['oauth_token'])); //standard oauth lib expects request token stdclass obj $request_token = (object) array('key' => $request_token_response['oauth_token'], 'secret' => $request_token_response['oauth_token_secret']); //cache token for retreival after auth file_put_contents('request_token.txt', serialize($request_token)); //redirect user for auth $redirect_url = sprintf('https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s&oauth_callback=%s', $request_token_response['oauth_token'], urlencode(OAUTH_CALLBACK_URL)); header('Location: ' . $redirect_url); }