Ruminations of an addled mind

Random ramblings about my thoughts

  • Meta

  • RSS DelphiFeeds.com

    • Hydra 4 and Oxygene January 2012 Releases February 1, 2012
      We’re hitting the ground running for 2012 and finished January with the first two product releases of the year. Hydra 4 Hydra 4 is a major new release for our .NET/Delphi cross-platform product, and one we’re very excited about. Hydra has been at version 3 for a while now and seen mostly ...
      RemObjects Blogs (marc hoffman)
    • Overview of RemObjects Hydra 4 February 1, 2012
      An overview of Hydra and what’s new in version 4, including support for Delphi XE2, FireMonkey, Silverlight and true 64-bit support.
      RemObjects Blogs (RemObjects TV)
    • No such pipe, or this pipe has been deleted February 1, 2012
      This data comes from pipes.yahoo.com but the Pipe does not exist or has been deleted.
      Boise Software Developers Group
    • Movie #66 - Animating Adding a TListBoxItem January 31, 2012
      This is another video where I demonstrate my limited knowledge of FireMonkey.  It it I build the classic "Add items from an Edit to a ListBox" example, then add a little animation to make things look pretty.   The video is a touch under 13 minutes and you can watch it here or on YouTube.  This video ...
      LearnDelphi.TV (cgg@christie.net.nz)
    • Projecting 3D points to a 2D screen coordinate system January 31, 2012
      In this article I will put forward a small function to project 3D points to a 2D coordinate system. I have used VLO framework to display all the points after the calculation of different common functions. The most difficult part is to correctly project 3D points into a 2D perspective. Basically the ...
      Random thoughts on coding (Jordi Corbilla)
    • February 14, 2012 - Celebrate Delphi’s 17th birthday during 3 live webinars January 31, 2012
      Delphi version 1.0 was launched at the Software Development Conference on February 14, 1995. The several thousand developers gave the team a standing ovation during the launch. This year we are celebrating 17 years of continuous innovation for the Delphi language, run-time library, Visual ...
      Sip from the Firehose (David Intersimone)
    • Rethinking the Delphi code editor January 31, 2012
      When you chose to use Delphi, you picked a great language with an absolutely perfect, flawless, IDE that couldn’t possibly be improved. Right? Wait, what’s that you’re saying? It’s NOT perfect? It CAN be improved? Ok, I admit, that was a lousy attention-getter to open with, ...
      TwoDesk Delphi Blog (jacob)
    • OmniThreadLibrary Documentation–an Outline January 31, 2012
      That’s how it’s going to look. If you feel I have left something out, now is the time to raise your voice. Introduction Introduction to Multithreading Introduction to OmniThreadLibrary Tasks vs. Threads Locking (vs.) Messaging TOmniValue High-level ...
      The Delphi Geek (gabr)
    • Delphi DataSnap REST server and jQueryMobile web client tutorial available January 31, 2012
      I have just put together a little EDN article about using jQueryMobile JavaScript library in your Delphi XE2 "DataSnap REST Application" projects. The idea was to demonstrate how to call server-side functions implemented in native Delphi code from the JavaScript client embedded in a web page using ...
      Pawel Glowacki (Pawel Glowacki)
    • Visiting Alabama January 31, 2012
      I've been on a trip to the US last week, and quite busy, so I didn't post to the blog for quite long. Trying to catch up now, but first a short summary of the trip. Last week I was for 5 days consulting in Birmingham, Alabama, at OneDomain. Very nice and successful company, fully focused on ...
      Marco's Tech Blog (marcocantu)

Always double-check your itinerary

Posted by chuckbeasley on May 19, 2009

I spent the last few days attending a conference in San Francisco.  The conference was Friday through Sunday.  I knew when I purchased my airline ticket the dates of the conference.  Imagine my surprise when I received an email, shortly after midnight Saturday morning, informing me that it was time to check-in for my flight.  I knew this couldn’t be correct because my flight wasn’t scheduled to leave until 12:35 a.m. May 18 or so I thought.  After a conversation with the airline’s customer service department, just before 1 a.m., I realized that I had purchased the ticket for the wrong date.  Now, I’m not going to sit here and blame the website or anything else.  I bought the ticket and failed to verify the date of the return trip.  So, learn from me to always double-check your itinerary before you click the purchase button.  Otherwise, have fun booking a one-way ticket back home!

Posted in Travel | Leave a Comment »

Using OAUTH for Delphi

Posted by chuckbeasley on April 29, 2009

Before attempting to use OAUTH, you must obtain a developer key and secret from the service provider.  In the sample code provided in this article, I have removed my developer key and secret.  No other code modifications have been made.

Step 1 – Request request token (step A in diagram)

procedure TForm1.RqsBtnClick(Sender: TObject);
var
URL: string;
endpos: integer;
begin
Key := ‘http://www.myspace.com/developerkey’;
Secret := ‘developersecret’;
URL := ‘http://api.myspace.com/request_token’;
// Create all objects
Consumer := TOAuthConsumer.Create(Key, Secret);
HMAC := TOAuthSignatureMethod_HMAC_SHA1.Create;

ARequest := TOAuthRequest.Create(URL);

ARequest := ARequest.FromConsumerAndToken(Consumer, nil, URL);
ARequest.Sign_Request(HMAC, Consumer, nil);
HTTPStream := TStringStream.Create(”);
URL := URL + ‘?’ + ARequest.GetString;
Response := idHTTP1.Get(URL);

endpos := AnsiPos(‘&oauth_token_secret=’, Response);
oauth_token := ”;
oauth_token := Copy(Response, 13, endpos-13);
Response := Copy(Response, endpos, Length(Response));

oauth_token_secret := Copy(Response, 21, Length(Response));
Token := TOAuthToken.Create(oauth_token, oauth_token_secret);
end;

The service provider responds by sending a token and token secret, which is parsed from the Response variable.

Step 2 – Authorize (Step C in diagram)

procedure TForm1.AuthBtnClick(Sender: TObject);
var
Callback_URL, URL :string;
begin
URL := ‘http://api.myspace.com/authorize’;
Callback_URL := ‘http://www.chuckbeasley.com’;
URL := URL + ‘?’ + ‘oauth_token=’ + oauth_token + ‘&’ + ‘oauth_token_secret=’ + oauth_token_secret +
‘&oauth_callback=’ + TOAuthUtil.urlEncodeRFC3986(Callback_URL);
EmbeddedWB1.Navigate(URL);
end;

The token, token secret, and call back URL are appended to the URL.  The service provider obtains user authorization and directs the consumer to the call back URL.

Step 3 – Request access token (Step E in diagram)

procedure TForm1.AccBtnClick(Sender: TObject);
var
endpos: integer;
URL: string;
begin
URL := ‘http://api.myspace.com/access_token’;
Consumer := nil;
Consumer := TOAuthConsumer.Create(Key, Secret, ‘http://www.chuckbeasley.com’);
ARequest.HTTPURL := URL;
ARequest := ARequest.FromConsumerAndToken(Consumer, Token, URL);
ARequest.Sign_Request(HMAC, Consumer, Token);
URL := URL + ‘?’ + ARequest.GetString;
Response := idHTTP1.Get(URL);
endpos := AnsiPos(‘&oauth_token_secret=’, Response);
oauth_token := ”;
oauth_token := Copy(Response, 13, endpos-13);
Response := Copy(Response, endpos, Length(Response));

oauth_token_secret := Copy(Response, 21, Length(Response));
Token := TOAuthToken.Create(oauth_token, oauth_token_secret);
end;

The service provider responds by sending an access token and token secret, which is parsed from the Response variable.

Step 4 – Access protected resources (Step G on diagram)

procedure TForm1.AccRscClick(Sender: TObject);

procedure process(o: ISuperObject);
var
f: TSuperObjectIter;
i: Integer;
begin
case ObjectGetType(o) of
stObject:
begin
Memo1.Lines.Add(‘{‘);
if ObjectFindFirst(o, f) then
repeat
keypair := f.key;
process(f.val)
until not ObjectFindNext(f);
ObjectFindClose(f);
Memo1.Lines.Add(‘}’);
end;
stArray:
begin
Memo1.Lines.Add(‘[');
for i := 0 to o.AsArray.Length - 1 do
process(o.AsArray.O[i]);
Memo1.Lines.Add(‘]’);
end;
stString:
begin
keypair := keypair + ‘:’ +(UTF8Decode(o.AsString));
Memo1.Lines.Add(keypair);
end;
stNull:
Memo1.Lines.add(‘nil’);
else
Memo1.Lines.add(o.AsString);
end;
end;
var
json: ISuperObject;
StringList: TStringList;
URL: string;
begin
URL := ‘http://api.myspace.com/v2/people/40250975/@friends?count=10000&format=json’;
Consumer := nil;
Consumer := TOAuthConsumer.Create(Key, Secret, ‘http://www.chuckbeasley.com’);
ARequest.HTTPURL := URL;
ARequest := ARequest.FromConsumerAndToken(Consumer, Token, URL);
ARequest.Sign_Request(HMAC, Consumer, Token);
URL := URL + ‘&’ + ARequest.GetString;
Response := idHTTP1.Get(URL);

StringList := TStringList.Create;
StringList.Add(Response);

json := TSuperObject.Create(stObject);
json.Merge(Response);
json := json.O['entry'];
Memo1.Lines.Clear;
process(json);
end;

This step assumes that the profile owner has authorized the application to access its protected data.  That can be performed by adding the application to the profile.

OAUTH for Delphi is available via SVN:   http://oauthdelphi.svn.sourceforge.net/.

Posted in Delphi | 2 Comments »

Catching up with technology

Posted by chuckbeasley on March 25, 2009

So, I’ve finally decided to write an entry in my blog.  In less than 2 weeks, I’ve join Twitter and begun blogging.  I’m not exactly sure what I’ll find to write about, but I’ll make it interesting.  Check back from time to time to see what things I find on the ‘net.

Posted in Uncategorized | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.