PHP code example of tehrancode / yahoo-api-bundle
1. Go to this page and download the library: Download tehrancode/yahoo-api-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tehrancode / yahoo-api-bundle example snippets
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new TehranCode\YahooApiBundle\TehranCodeYahooApiBundle(),
);
}
// app/config/config.yml
tehran_code_yahoo_api:
application_id: %Your_Application_ID%
consumer_key: %Your_Application_consumer_key%
consumer_secret: %Your_Application_consumer_secret%
callback_url: %Your_Application_callback_url%
$YahooService = $this->get('TehranCode.Yahoo.OAuth.Application');
$callback = %Your_Application_callback_url%;
# Fetch request token
$request_token = $YahooService->getRequestToken($callback);
$session = $request->getSession();
$session->set('request_token_key', $request_token->key);
$session->set('request_token_secret', $request_token->secret);
# Redirect user to authorization URL
$redirect_url = $YahooService->getAuthorizationUrl($request_token);
$YahooService = $this->get('TehranCode.Yahoo.OAuth.Application');
$session = $request->getSession();
$request_token = new \OAuthToken($session->get('request_token_key'), $session->get('request_token_secret'));
# Exchange request token for authorized access token
$access_token = $YahooService->getAccessToken($request_token, $_REQUEST['oauth_verifier']);
# update access token
$YahooService->setAccessToken($access_token);
# fetch user profile
$Profile = $YahooService->getProfile();
# fetch user Contacts
$Contacts = $YahooService->getContacts();
var_dump($Profile);
var_dump($Contacts);
$YahooService = $this->get('TehranCode.Yahoo.OAuth.Application');
$callback = %Your_Application_callback_url%;
$OpenIDUrl = $YahooService->getOpenIDUrl($callback);
if(isset($_REQUEST['openid_mode']))
{
$YahooService = $this->get('TehranCode.Yahoo.OAuth.Application');
if($_REQUEST['openid_mode'] == 'id_res')
{
// validate claimed open id
// extract approved request token from open id response
$request_token = new \YahooOAuthRequestToken($_REQUEST['openid_oauth_request_token'], '');
// exchange request token for access token
$access_token = $YahooService->getAccessToken($request_token);
$YahooService->setAccessToken($access_token);
$Contacts = $YahooService->getContacts();
$Profile = $YahooService->getProfile();
//You can access OpenID response
var_dump($_REQUEST['openid_ax_value_email']);
var_dump($_REQUEST['openid_ax_value_language']);
//You can also access OAuth response
var_dump($Contacts);
var_dump($Profile);
//...
}
}