Ruminations of an addled mind

Random ramblings about my thoughts

  • Meta

  • RSS DelphiFeeds.com

    • Getting to grips with using FireMonkey Grids May 29, 2012
      Although there is a huge amount that is the same for Delphi and C++ Builder developers between VCL and FireMonkey, one thing that has changed is the FireMonkey grids. FireMonkey Grid Example After a recent question at an event, I thought I would put a little demo together to help understand some of ...
      Stephen Ball (Stephen Ball)
    • Italian Delphi Day 2012 on June 7th May 29, 2012
      Next week I'm hosting a 3-days Delphi event in Piacenza, Italy. This is the largest independent gathering of Italian Delphi developers, now in its 11th year. The main event is on June 7th, with a conference in the morning and discussion panels in the afternoon. Speakers include: ...
      Marco's Tech Blog (marcocantu)
    • Fields default values, anonymous records May 29, 2012
      Recent additions to DWScript… as well as for next Smart MS version Fields default values Record and class fields can now have default values, and can be type-inferenced. The same syntax works both in record declarations and class declarations, and you can use ‘=’ or ...
      DelphiTools (Eric)
    • What you need on your Mac to develop for OS X or iOS using Delphi XE2 May 29, 2012
      Just a few notes on things I told Delphi cross development students over the last nine months or so. For Mac OS X apps: The Platform Assistant Server that ships with Delphi XE2 For iOS apps: Steps: Become a registered Apple Developer Download and install xCode 4 when you run on OS X 10.7 Lion or ...
      The Wiert Corner (jpluimers)
    • The Emperors New Native – pt. 2 May 28, 2012
      Marc Hoffman kindly took the time to respond to my previous post and prompted me to re-formulate and expand my observations on Jim McKeeths post (which never made it to the comments thread on the RO blog for reasons best known to The Cloud). The biggest issue I had with Jim’s post in ...
      Te Waka o Delphi (Deltics)
    • Hi-res screenshots and creating a book index – any ideas? May 28, 2012
      It’s been nearly a month since I blogged about the Delphi book I’ve been writing, and in between times, CreateSpace (Amazon’s ‘print on demand’ subsidiary) have become a lot more attractive for a UK-based would-be author like myself. So more attractive, in fact, that I ...
      Delphi Haven (Chris Rolliston)
    • XE Plus Pack – Release 8 (XE and XE2 versions) May 28, 2012
      JED Software Blog (JED)
    • JSDialog Pack 2.0.019 May 28, 2012
      JED Software Blog (JED)
    • Delphi Day Italy - 6th to 8th June May 28, 2012
      If your in around Piacenza, then you may want to watch out for the upcoming Delphi Day event in Italy. Delphi Day is the annual meeting of Italian Delphi developers with sessions over 3 days. I’ll be there on the 7th June along with Marco Cantu and others. Registration is from €30 - visit ...
      Stephen Ball (Stephen Ball)
    • Metro Development with Oxygene for .NET May 28, 2012
      Windows 8 introduces the new Metro style for app development. These Metro apps take advantage of the new Windows Runtime (WinRT) and are available on both Windows 8 desktop and Windows 8 Tablets. Of course Windows 8 has preliminary support in Prism XE2.5 and Oxygene for .NET 5.1. To get started you ...
      RemObjects Blogs (Jim McKeeth)

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.