PHP, OAuth &
Web Services
   By James Broad
You will learn

• How to authenticate a request using
  OAuth
• How to use a PHP framework -
  CodeIgniter
• How to retrie...
Technologies covered

• SVN
• rsync
• PHP
• CodeIgniter
Project : Search
• Search a number of services using their
  Web Service API’s
  • Twitter
  • Flickr
  • Yahoo Search
  •...
YQL
Yahoo Query Language
YQL Console
http://developer.yahoo.com/yql/console/
SWEET!
Now how do I make use of it?
Copy the generated
   URL and go
Nope. Soz, you need
  authentication
    In the flavour of OAuth
What is OAuth?
  I will attempt to explain
The problem


http://www.flickr.com/photos/fabricio/2354662901/   http://www.flickr.com/photos/borkazoid/3219646418/




   ...
One Solution - OAuth
OAuth Flow
Demonstration

• Manual 3 Leg OAuth process
 • http://carbonsilk.com/oauth/example/
    client.php
• Our example uses 2 Le...
Getting Started

• Getting our development environment set
  up
• Obtaining our application keys
• Covering the PHP code n...
Development
        Environment
• XAMPP - http://www.apachefriends.org/en/
  xampp.html
• CodeIgniter Framework
• OAuth Li...
Installing CodeIgniter
svn checkout http://dev.ellislab.com/svn/CodeIgniter/trunk ~/
                    Sites/project_sea...
Configuring
          CodeIgniter
• Check it works http://localhost/
  project_search/
• Can we have pretty URLs? Please?
 ...
OAuth PHP Library

• svn co http://oauth.googlecode.com/svn/
  code/php ~/Sites/oauth/
• Copy OAuth.php to CodeIgniter Lib...
YQL / OAuth Classes
I have been nice enough to pre-bake some classes for
                        you
YQL / OAuth Classes
• system/application/libraries/yql_lib.php
 • Copy & Paste from http://gist.github.com/
    57536
• sy...
Obtaining Application
         Keys
• Go to https://developer.yahoo.com/
  dashboard/ and register a new OAuth
  applicati...
Configuring Our App


• Open system/application/libraries/yql_lib.php
 • Add your OAuth key and secret
Upload

• We need to upload to the domain
  registered earlier for authentication
• rsync -r --progress ~/Sites/project_se...
Review our framework
        code
 We look behind what has been installed - The
    CodeIgniter Libraries and controllers
Live Code Time
Adding a new query - Scraping the Finance news top
  stories and presenting them using a view and a
       ...
Thanks!
twitter.com/kulor
 carbonsilk.com
Upcoming SlideShare
Loading in...5
×

PHP, OAuth, Web Services and YQL

6,333

Published on

Slides from a presentation (at YDN Tuesdays) on how to use YQL using OAuth, CodeIgniter (PHP MVC framework) and external web services. To get the code mentioned in this presentation go to http://github.com/kulor/yql_php/tree

Published in: Technology
1 Comment
8 Likes
Statistics
Notes
No Downloads
Views
Total Views
6,333
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
177
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide

PHP, OAuth, Web Services and YQL

  1. 1. PHP, OAuth & Web Services By James Broad
  2. 2. You will learn • How to authenticate a request using OAuth • How to use a PHP framework - CodeIgniter • How to retrieve web services using YQL
  3. 3. Technologies covered • SVN • rsync • PHP • CodeIgniter
  4. 4. Project : Search • Search a number of services using their Web Service API’s • Twitter • Flickr • Yahoo Search • Wikipedia
  5. 5. YQL Yahoo Query Language
  6. 6. YQL Console http://developer.yahoo.com/yql/console/
  7. 7. SWEET! Now how do I make use of it?
  8. 8. Copy the generated URL and go
  9. 9. Nope. Soz, you need authentication In the flavour of OAuth
  10. 10. What is OAuth? I will attempt to explain
  11. 11. The problem http://www.flickr.com/photos/fabricio/2354662901/ http://www.flickr.com/photos/borkazoid/3219646418/ • http://adactio.com/journal/1357
  12. 12. One Solution - OAuth
  13. 13. OAuth Flow
  14. 14. Demonstration • Manual 3 Leg OAuth process • http://carbonsilk.com/oauth/example/ client.php • Our example uses 2 Leg - no need for the user to leave the page but we only get access to public information.
  15. 15. Getting Started • Getting our development environment set up • Obtaining our application keys • Covering the PHP code needed to run our application
  16. 16. Development Environment • XAMPP - http://www.apachefriends.org/en/ xampp.html • CodeIgniter Framework • OAuth Library • CodeIgniter OAuth Classes
  17. 17. Installing CodeIgniter svn checkout http://dev.ellislab.com/svn/CodeIgniter/trunk ~/ Sites/project_search
  18. 18. Configuring CodeIgniter • Check it works http://localhost/ project_search/ • Can we have pretty URLs? Please? • change system/applications/config/config.php • $config['index_page'] = quot;quot;; • Add .htaccess file
  19. 19. OAuth PHP Library • svn co http://oauth.googlecode.com/svn/ code/php ~/Sites/oauth/ • Copy OAuth.php to CodeIgniter Library - system/applications/libraries/ • Change line 369 of OAuth.php - Realm bug. Add realm as a parameter
  20. 20. YQL / OAuth Classes I have been nice enough to pre-bake some classes for you
  21. 21. YQL / OAuth Classes • system/application/libraries/yql_lib.php • Copy & Paste from http://gist.github.com/ 57536 • system/application/controllers/yql.php • Copy & Paste from http://gist.github.com/ 57535
  22. 22. Obtaining Application Keys • Go to https://developer.yahoo.com/ dashboard/ and register a new OAuth application • One I made earlier: https:// developer.yahoo.com/dashboard/ success.html?key=xxx
  23. 23. Configuring Our App • Open system/application/libraries/yql_lib.php • Add your OAuth key and secret
  24. 24. Upload • We need to upload to the domain registered earlier for authentication • rsync -r --progress ~/Sites/project_search/ you@yoursite.com:~/public_html/ project_search/
  25. 25. Review our framework code We look behind what has been installed - The CodeIgniter Libraries and controllers
  26. 26. Live Code Time Adding a new query - Scraping the Finance news top stories and presenting them using a view and a controller
  27. 27. Thanks! twitter.com/kulor carbonsilk.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×