Skip to content

Instantly share code, notes, and snippets.

@ydn
Created April 1, 2010 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydn/352518 to your computer and use it in GitHub Desktop.
Save ydn/352518 to your computer and use it in GitHub Desktop.
sample code for making an oauth request using YAP OAuth credentials
<?php // sample code for making an oauth request using YAP OAuth credentials
// http://oauth.googlecode.com/svn/code/php/OAuth.php
require 'OAuth.php';
// get key/secret from your app dashboard http://developer.apps.yahoo.com/projects
$key="exampleGWklXQ3FTSk1iJmQ9WVdrOVYyOVlhMjR4TnpnbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yNQ--";
$secret="examplec1a002564a746354ff159380b9d689";
$consumer = new OAuthConsumer($key, $secret);
// http://developer.yahoo.com/yql/console/?q=select%20*%20from%20social.profile%20where%20guid%3Dme
$http_method = 'GET';
$http_url = 'http://query.yahooapis.com/v1/yql';
$parameters = array(
'q'=>'select * from social.profile where guid=me',
'format' => 'json'
);
// oauth lib expects std object
$token = (object) array(
'key' => $_POST['yap_viewer_access_token'],
'secret' => $_POST['yap_viewer_access_token_secret']
);
$req = OAuthRequest::from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req->sign_request($sig_method, $consumer, $token);//note: double entry of token
$ch = curl_init($req->to_url());
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = json_decode( curl_exec($ch) );
curl_close($ch);
?>
<pre>
<? print_r( $response ) ?>
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment