php, oauth, web services and yql
DESCRIPTION
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/treeTRANSCRIPT
![Page 1: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/1.jpg)
PHP, OAuth & Web Services
By James Broad
![Page 2: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/2.jpg)
You will learn
• How to authenticate a request using OAuth
• How to use a PHP framework - CodeIgniter
• How to retrieve web services using YQL
![Page 3: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/3.jpg)
Technologies covered
• SVN
• rsync
• PHP
• CodeIgniter
![Page 4: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/4.jpg)
Project : Search
• Search a number of services using their Web Service API’s
• Flickr
• Yahoo Search
• Wikipedia
![Page 5: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/5.jpg)
YQLYahoo Query Language
![Page 6: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/6.jpg)
YQL Consolehttp://developer.yahoo.com/yql/console/
![Page 7: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/7.jpg)
SWEET!Now how do I make use of it?
![Page 8: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/8.jpg)
Copy the generated URL and go
![Page 9: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/9.jpg)
Nope. Soz, you need authentication
In the flavour of OAuth
![Page 10: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/10.jpg)
What is OAuth?I will attempt to explain
![Page 11: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/11.jpg)
The problem
• http://adactio.com/journal/1357
http://www.flickr.com/photos/borkazoid/3219646418/http://www.flickr.com/photos/fabricio/2354662901/
![Page 12: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/12.jpg)
One Solution - OAuth
![Page 13: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/13.jpg)
OAuth Flow
![Page 14: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/14.jpg)
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.
![Page 15: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/15.jpg)
Getting Started
• Getting our development environment set up
• Obtaining our application keys
• Covering the PHP code needed to run our application
![Page 16: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/16.jpg)
Development Environment
• XAMPP - http://www.apachefriends.org/en/xampp.html
• CodeIgniter Framework
• OAuth Library
• CodeIgniter OAuth Classes
![Page 17: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/17.jpg)
Installing CodeIgnitersvn checkout http://dev.ellislab.com/svn/CodeIgniter/trunk ~/
Sites/project_search
![Page 18: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/18.jpg)
Configuring CodeIgniter
• Check it works http://localhost/project_search/
• Can we have pretty URLs? Please?
• change system/applications/config/config.php
• $config['index_page'] = "";
• Add .htaccess file
![Page 19: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/19.jpg)
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
![Page 20: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/20.jpg)
YQL / OAuth ClassesI have been nice enough to pre-bake some classes for
you
![Page 21: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/21.jpg)
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
![Page 22: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/22.jpg)
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
![Page 23: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/23.jpg)
Configuring Our App
• Open system/application/libraries/yql_lib.php
• Add your OAuth key and secret
![Page 24: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/24.jpg)
Upload
• We need to upload to the domain registered earlier for authentication
• rsync -r --progress ~/Sites/project_search/ [email protected]:~/public_html/project_search/
![Page 25: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/25.jpg)
Review our framework code
We look behind what has been installed - The CodeIgniter Libraries and controllers
![Page 26: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/26.jpg)
Live Code TimeAdding a new query - Scraping the Finance news top
stories and presenting them using a view and a controller
![Page 27: PHP, OAuth, Web Services and YQL](https://reader033.vdocuments.site/reader033/viewer/2022060110/5560bf03d8b42a033c8b5431/html5/thumbnails/27.jpg)
Thanks!twitter.com/kulorcarbonsilk.com