After registering your app (see Developer and Application Registration)
with the API provider and obtaining an OAuth client ID and client secret,
its time to start writing code! Lets go through each step of the flow
and show how the protocol works. Well use PHP as the example programming
language and the Google
Tasks API along with Googles OAuth
2.0 authorization server.
Although well write the PHP code using the raw OAuth protocol, many
API providers distribute client libraries for accessing their services.
These libraries abstract away some of the details of implementing OAuth
2.0 and make it easier for developers. You can find information on
Googles PHP library, which works with Google Tasks, Google+, and many
other Google APIs, at code.google.com.
Since the OAuth flow involves directing your users to the website
of the API provider to obtain authorization, its a best practice to let
them know in advance what will happen. You can do this by displaying a
message, along with a link (the Add tasks to your Google Tasks link in
During the time I studied golf, I participated in a six-week group golf class. Each week, five of us, all adults, would meet at the driving range for an hour of instruction followed by an hour of practice on our own. At the beginning of the third session, I was sitting on a bench waiting for the class ahead of ours to finish. Next to me was one of my classmates, who had also gotten there early. I had learned, when we had introduced ourselves on the first day, that she was heavily involved in the corporate routine and wanted to learn golf both for relaxation and as a means to further her career. She explained that many times in the course of her job, golf outings were offered as a way to meet new business contacts and discuss company matters in a relaxed setting.
As we chatted about golf and our jobs, I asked her this question: “Well, did you practice what we learned last week?” “No,” she replied. “I had so much to do all week. I just want to wake up one morning and be able to play well.” I sensed frustration and mild depression in her voice. She seemed frustrated that golf was much harder than it looked and depressed about all the hard work that lay ahead of her if she had any hopes of reaching the level of ability that she felt would make the game more fun.