27
PHP, OAuth & Web Services By James Broad

PHP, OAuth, Web Services and YQL

  • Upload
    kulor

  • View
    6.277

  • Download
    3

Embed Size (px)

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/tree

Citation preview

Page 1: PHP, OAuth, Web Services and YQL

PHP, OAuth & Web Services

By James Broad

Page 2: PHP, OAuth, Web Services and YQL

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

Technologies covered

• SVN

• rsync

• PHP

• CodeIgniter

Page 4: PHP, OAuth, Web Services and YQL

Project : Search

• Search a number of services using their Web Service API’s

• Twitter

• Flickr

• Yahoo Search

• Wikipedia

Page 5: PHP, OAuth, Web Services and YQL

YQLYahoo Query Language

Page 6: PHP, OAuth, Web Services and YQL

YQL Consolehttp://developer.yahoo.com/yql/console/

Page 7: PHP, OAuth, Web Services and YQL

SWEET!Now how do I make use of it?

Page 8: PHP, OAuth, Web Services and YQL

Copy the generated URL and go

Page 9: PHP, OAuth, Web Services and YQL

Nope. Soz, you need authentication

In the flavour of OAuth

Page 10: PHP, OAuth, Web Services and YQL

What is OAuth?I will attempt to explain

Page 12: PHP, OAuth, Web Services and YQL

One Solution - OAuth

Page 13: PHP, OAuth, Web Services and YQL

OAuth Flow

Page 14: PHP, OAuth, Web Services and YQL

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

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

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

Installing CodeIgnitersvn checkout http://dev.ellislab.com/svn/CodeIgniter/trunk ~/

Sites/project_search

Page 18: PHP, OAuth, Web Services and YQL

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

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

YQL / OAuth ClassesI have been nice enough to pre-bake some classes for

you

Page 21: PHP, OAuth, Web Services and YQL

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 23: PHP, OAuth, Web Services and YQL

Configuring Our App

• Open system/application/libraries/yql_lib.php

• Add your OAuth key and secret

Page 24: PHP, OAuth, Web Services and YQL

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

Review our framework code

We look behind what has been installed - The CodeIgniter Libraries and controllers

Page 26: PHP, OAuth, Web Services and YQL

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

Thanks!twitter.com/kulorcarbonsilk.com