human art and other bits


Signing into the TradeMe API with PHP and ZendFramework Oauth

, posted: 27-Jan-2011 22:47

I have recently been playing with the new TradeMe API,  it uses the OAuth system to login. Which is pretty cool as it lets anyone build applications that use the TradeMe API without the need of the users to give up their Username or Passwords.
 
I have worked out how to do this with the help of Zend Frameworks Oauth Documentation,
the WebHole blog post titled Zend OAuth with Twitter and of course the TradeMe API documentation.
 
The code example below has a lot of extra print_r and echo statements, these  help  display what is going on.
There are three files main.php, oauthconfig.php and callback.php
Feel free to ask questions.  I hope to write more about the Trademe API as I start to understand it.
 
main.php
1: 5: TradeMe OAuth Login 6:   9: <?php 10: session_start(); 11: // include the oauth consumer class 12: require_once 'Zend/Oauth/Consumer.php'; 13: require_once 'oauthconfig.php'; 14:   15: echo 'config object'; 16: print_r($config); 17: 18: // create oauth object 19: $oauth=new Zend_Oauth_Consumer($config); 20:   21: echo 'oauth object'; 22: print_r($oauth); 23: 24:   25: echo 'request token'; 26:   27: // get request token 28: try{ 29: $request_token = $oauth->getRequestToken(); 30: } 31: catch(Exception $e) 32: { 33: echo 'Error: '.$e->getMessage(); 34: print_r($e); // show debug infomation 35: exit (1); 36: } 37: // store request token in session 38: $_SESSION['request_token']=serialize($request_token); 39:   40: echo '<br>the request token: '.$request_token; 41:   42: // explode request token to extract oauth token 43: $exploded_request_token=explode('=',str_replace('&','=',$request_token)); 44: // get oauth token from exploded request token 45: $oauth_token=$exploded_request_token[1]; 46: echo '
the exploded request token a<br>'; 47: print_r($exploded_request_token); 48: echo '<br><br>'; 49:   50: echo 'request trademe for Authorized token.<br>'; 51: // show sign in link 52: echo "< a href='https://secure.trademe.co.nz/Oauth/Authorize?oauth_token={$oauth_token}'>
request authorize"; 53:   54: ?>  
oauthconfig.php
0: $consumerKey='consumer key provided by trademe'; 0a: $consumerSecret='consumer secret key provided by trademe'; 0b: $config=array( 1: 'requestScheme' =>Zend_Oauth::REQUEST_SCHEME_HEADER, 12: 'version'=>'1.0', 13: 'signatureMethod'=>'HMAC-SHA1', 14: 'callbackUrl' => 'http://localhost/TradeMeAPI/callback.php', // where to go after authorized 15: 'siteUrl' => 'https://secure.trademe.co.nz/Oauth/', 16: 'requestTokenUrl' => 'https://secure.trademe.co.nz/Oauth/RequestToken', 17: 'userAuthorisationUrl' => 'https://secure.trademe.co.nz/Oauth/Authorize', 18: 'accessTokenUrl' => 'https://secure.trademe.co.nz/Oauth/AccessToken', 19: 'consumerKey'=>$consumerKey, 20: 'consumerSecret'=>$consumerSecret, 21: 'oauth_timestamp'=>time(), 22: 'oauth_nonce'=>rand(1, 1000000), 23: 24: 'oauth_signature'=>'' 25: ); 26: ?>  
callback.php
1: we have callback'; 7:   8: session_start(); 9: require_once 'Zend/Oauth/Consumer.php'; 10: require_once 'oauthConfig.php'; 11:   12: $oauth = new Zend_Oauth_Consumer($config); 13:   14: if (isset($_GET['oauth_token']) && isset($_SESSION['request_token'])) { 15: try{ 16: $access = $oauth->getAccessToken($_GET, unserialize($_SESSION['request_token'])); 17: } 18: catch(Exception $e) 19: { 20: echo 'Error: '.$e->getMessage(); 21: exit (1); 22: } 23:   24: echo 'access tokens'; 25: echo $access; 26: $_SESSION['access_token'] = serialize($access); 27: $_SESSION['request_token'] = null; 28:   29: /* 30: * 31: * This is where the trademe interactions happen 32: * 33: */ 34:   35: }elseif(!empty($_GET['denied'])){ 36: echo 'you have denied us access to your trademe crendentials'; 37: } 38: else { 39: echo 'Invalid callback request. Oops. Sorry.'; 40: } 41: ?>



Blog Posts with Windows Live Writer

, posted: 27-Jan-2011 16:55

This is a bit of a test into using Windows Live Writer with the  Geekzone blogging system.
Once I have downloaded and installed Live Write the setup process was pretty easy.
 

First I selected Other services to use Geekzone.
 

The I set the web blog address: https://metaweblog.geekzone.co.nz/MetaWebLog.axd
And entered my User name and password.
 

Then I was asked to select blog type.
 

The final step was to Select my blog,  too easy.
 
Then all I needed to do was compose a post and publish.
Thanks to all who made this possible.
Help taken from this Geekzone thread



Why I wont be voting for Slingshot in the Netguide best ISP award.

, posted: 15-Jun-2010 19:48

Why, because of the way your providing such a poor quality youtube performance. Their caching system is billing users for more data than necessary, if I watch a youtube clip on twitter and then click watch on youtube, Slingshot sends/bills me for another copy of the clip, when it' should use the browsers cached version. That's such a rip off. When calling the helpdesk, it takes around 30 mins or more than an hour if the centre is busy, they also say they will call back and it's very rare that they do. Their website doesn't clearly list the details, ie, big mouth calling plans, say unlimited, but it's really 80 hours. The free data periods say from 1am-7am have a random 15mins boundary, so that users can be billed for extra data at the start or end of their free data periods. So, no, I will not be voting for Slingshot in the NetGuide best ISP award.



Call in data AJAX style thanks to JQuery

, posted: 24-Apr-2010 07:00

The way AJAX has the ability to load in extra data into a website without reloading the whole web page, has always given me a buzz. Now with the help of jquery .load() page it's become possible for even me to make a page function in that classic AJAX style. The code below is taken from my work on a php twitter app. What I got it to do was, expand tweets that are replies when clicked. It passes the ID of the Tweet to fetch when it calls the getTweet.php file. Over view of the code below. Line 20: has a Div with the id of the Tweet that was replied too. There also is the onclick function that calls the getTweet function when clicked. Line7: Is the GetTweet script. Line9-11 is just an alert if the file requested fails. Line8: Does all the work, It gets the id of the div that was clicked and passes it when loading the file to the file getTweet.php the code To get code, visit here. Thanks to Regs for the help.



Unboxing of New ASUS netbook 1001HA from Harvey Norman nz

, posted: 28-Jan-2010 17:02

I got myself a new netbook,  I could hardly resit Harvey Normans boxing day special, $288 for a netbook.

So here is the unboxing.










And some details;



hellonearthisman's profile

Brett Cooper
Feilding
New Zealand


Stone artist with a digital understanding. 1st computer was a c=64