Your SlideShare is downloading. ×
Integrating WordPress With Web APIs
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Integrating WordPress With Web APIs

624
views

Published on

Published in: Technology, Business

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
624
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Integrating WordPressWith Web APIsRandy Hoyt
  • 2. #wpsummit @randyhoyt@randyhoytRandy Hoyt randyhoyt.com@randyhoytPresentation randyhoyt.com/wpsummit13About Me
  • 3. #wpsummit @randyhoyt@randyhoyt• APIs: Defined• Two Examples:1. Get Treehouse Badges2. Get ShopLocket Products• WordPress FunctionsOverview
  • 4. API
  • 5. Application Programming Interface
  • 6. A point where two systems,subjects, organizations, etc.,meet and interact.Interface, http://dictionary.com/browse/interface
  • 7. [Keyboard]
  • 8. [Remote Control]
  • 9. [Lock and Key]
  • 10. An interface for softwarecomponents to communicatewith each other.Wikipedia: API, http://trhou.se/defineAPI
  • 11. #wpsummit @randyhoyt@randyhoyt•Android SDK: Camera APIAPI Examples
  • 12. import android.hardware.Camera;Camera.getNumberOfCameras();Camera.open(cameraId);
  • 13. #wpsummit @randyhoyt@randyhoyt•Android SDK: Camera API•WordPress: Plugin APIAPI Examples
  • 14. <?php/*Plugin Name: Treehouse BadgesDescription: Displays the badges ...Version: 1.0*/?>add_action(init,treehouse_badges_init);...
  • 15. #wpsummit @randyhoyt@randyhoyt•Android SDK: Camera API•WordPress: Plugin API•HTML5: Canvas APIAPI Examples
  • 16. var canvas = document.getElementById("canvas");var context = canvas.getContext("2d");context.fillRect(10, 10, 40, 380, "#000000");context.drawImage(img, x, y, 100, 77);
  • 17. Web APIs
  • 18. REST
  • 19. Representational State Transfer
  • 20. RESTful API
  • 21. Example #1: Treehouse
  • 22. [Treehouse screenshot]
  • 23. JavaScript Object Notation:Text-based open standarddesigned for human-readabledata interchange.Wikipedia: JSON, http://trhou.se/defineJSON
  • 24. {"firstName": "John","lastName": "Smith","address": {"streetAddress": "21 2nd Street","city": "New York","state": "NY","postalCode": 10021},"phoneNumber": [{"type": "home","number": "212 555-1234"},{"type": "fax","number": "646 555-4567"}]}Wikipedia: JSON, http://trhou.se/defineJSON
  • 25. [Treehouse JSON]
  • 26. [HTML]
  • 27. Asynchronous JavaScript and XML:Technique used by the browser toretrieve data from a server in thebackground without interfering withthe existing pageWikipedia: Ajax, http://trhou.se/defineAJAX
  • 28. [AJAX Request Code]
  • 29. [Badge Code]
  • 30. [Badge Display]
  • 31. <?php$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1,CURLOPT_URL => http://teamtreehou...));$resp = curl_exec($curl);curl_close($curl);?>
  • 32. GET  Request  with  WordPress  HTTP  APIWordPress, http://codex.wordpress.org/HTTP_API
  • 33. #wpsummit @randyhoyt@randyhoyt• GET• POST• PUT• DELETEREST: Types of Requests(Read)(Create)(Update)(Delete)
  • 34. #wpsummit @randyhoyt@randyhoyt•Does it have tobe real time?•What if somethinggoes wrong?API Questions
  • 35. Example #2: ShopLocket
  • 36. [Screenshot of WP]
  • 37. [Screenshot of WordPress]
  • 38. [Screenshot of Product Picker]
  • 39. [Screenshot of Product Picker]
  • 40. [Screenshot of Shortcode]
  • 41. [Screenshot of Website]
  • 42. Authentication
  • 43. OAuthAn open protocol to allow secureauthorization in a simple and standardmethod from web, mobile and desktopapplications.OAuth, http://oauth.net/
  • 44. App ID5f4a89f2d6655ac7a8859343d6d152579410e7b659b200e00aaf3721cf46269eApp Secretfa963a1ef3702c16d934500f7621697e2d6bfd05d3ef1751a32bdeb2a0599020
  • 45. [ShopLocket]
  • 46. [ShopLocket Login]
  • 47. [ShopLocket]
  • 48. /? code = 53fe... & state = auth...
  • 49. [GET Request]$args = array("code" => $_GET["code"],"app_id" => "app id","app_secret" => "app secret",);$response = wp_remote_post(https://www.shoplocket.com/. oauth/token,$args);
  • 50. Token:310826b20a535a422ccaa46d65c7065f83e403b9218a38962ab4e43021b93585
  • 51. [Token]
  • 52. #wpsummit @randyhoyt@randyhoyt•Does it have tobe real time?•What if somethinggoes wrong?API Questions
  • 53. [Refresh Button]
  • 54. WordPress Functions
  • 55. WordPress wp_ajax, http://trhou.se/wp_ajax_hook
  • 56. GET  Request  with  WordPress  HTTP  APIWordPress HTTP API, http://codex.wordpress.org/HTTP_API
  • 57. WordPress update_option, http://trhou.se/update_option
  • 58. Transients?WordPress, http://codex.wordpress.org/Transients_API
  • 59. TLC Transientshttp://github.com/markjaquith/WP-TLC-Transients
  • 60. Integrating WordPressWith Web APIsRandy Hoyt randyhoyt.com@randyhoytPresentation randyhoyt.com/wpsummit13
  • 61. [Screenshot of Cultivatr]
  • 62. [Screenshot of Edit Screen]
  • 63. [Screenshot of Date Picker]
  • 64. [Diagram]
  • 65. @randyhoyt•Does it have tobe real time?•What if somethinggoes wrong?API Questions
  • 66. @randyhoyt• GET• POST• PUT• DELETEREST: Types of Requests(Read)(Create)(Update)(Delete)
  • 67. require  ../tmhOAuth.php;require  ../tmhUtilities.php;$tw  =  new  tmhOAuth(array(    consumer_key        =>  APP_ID,    consumer_secret  =>  APP_SECRET,    user_token            =>  A_USER_TOKEN,    user_secret          =>  A_USER_SECRET,));$code  =  $tw-­‐>request(                        POST,                        $tw-­‐>url(1/statuses/update),                        array(status  =>  My  Tweet)                  );Twitter Libraries, https://dev.twitter.com/docs/twitter-libraries
  • 68. Integrating WordPressWith Web APIsRandy Hoyt randyhoyt.com@randyhoytPresentation randyhoyt.com/wpsummit13