Integrating WordPress With Web APIs

1,312 views

Published on

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,312
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Integrating WordPress With Web APIs

  1. 1. Integrating WordPressWith Web APIsRandy Hoyt
  2. 2. #wpsummit @randyhoyt@randyhoytRandy Hoyt randyhoyt.com@randyhoytPresentation randyhoyt.com/wpsummit13About Me
  3. 3. #wpsummit @randyhoyt@randyhoyt• APIs: Defined• Two Examples:1. Get Treehouse Badges2. Get ShopLocket Products• WordPress FunctionsOverview
  4. 4. API
  5. 5. Application Programming Interface
  6. 6. A point where two systems,subjects, organizations, etc.,meet and interact.Interface, http://dictionary.com/browse/interface
  7. 7. [Keyboard]
  8. 8. [Remote Control]
  9. 9. [Lock and Key]
  10. 10. An interface for softwarecomponents to communicatewith each other.Wikipedia: API, http://trhou.se/defineAPI
  11. 11. #wpsummit @randyhoyt@randyhoyt•Android SDK: Camera APIAPI Examples
  12. 12. import android.hardware.Camera;Camera.getNumberOfCameras();Camera.open(cameraId);
  13. 13. #wpsummit @randyhoyt@randyhoyt•Android SDK: Camera API•WordPress: Plugin APIAPI Examples
  14. 14. <?php/*Plugin Name: Treehouse BadgesDescription: Displays the badges ...Version: 1.0*/?>add_action(init,treehouse_badges_init);...
  15. 15. #wpsummit @randyhoyt@randyhoyt•Android SDK: Camera API•WordPress: Plugin API•HTML5: Canvas APIAPI Examples
  16. 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. 17. Web APIs
  18. 18. REST
  19. 19. Representational State Transfer
  20. 20. RESTful API
  21. 21. Example #1: Treehouse
  22. 22. [Treehouse screenshot]
  23. 23. JavaScript Object Notation:Text-based open standarddesigned for human-readabledata interchange.Wikipedia: JSON, http://trhou.se/defineJSON
  24. 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. 25. [Treehouse JSON]
  26. 26. [HTML]
  27. 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. 28. [AJAX Request Code]
  29. 29. [Badge Code]
  30. 30. [Badge Display]
  31. 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. 32. GET  Request  with  WordPress  HTTP  APIWordPress, http://codex.wordpress.org/HTTP_API
  33. 33. #wpsummit @randyhoyt@randyhoyt• GET• POST• PUT• DELETEREST: Types of Requests(Read)(Create)(Update)(Delete)
  34. 34. #wpsummit @randyhoyt@randyhoyt•Does it have tobe real time?•What if somethinggoes wrong?API Questions
  35. 35. Example #2: ShopLocket
  36. 36. [Screenshot of WP]
  37. 37. [Screenshot of WordPress]
  38. 38. [Screenshot of Product Picker]
  39. 39. [Screenshot of Product Picker]
  40. 40. [Screenshot of Shortcode]
  41. 41. [Screenshot of Website]
  42. 42. Authentication
  43. 43. OAuthAn open protocol to allow secureauthorization in a simple and standardmethod from web, mobile and desktopapplications.OAuth, http://oauth.net/
  44. 44. App ID5f4a89f2d6655ac7a8859343d6d152579410e7b659b200e00aaf3721cf46269eApp Secretfa963a1ef3702c16d934500f7621697e2d6bfd05d3ef1751a32bdeb2a0599020
  45. 45. [ShopLocket]
  46. 46. [ShopLocket Login]
  47. 47. [ShopLocket]
  48. 48. /? code = 53fe... & state = auth...
  49. 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. 50. Token:310826b20a535a422ccaa46d65c7065f83e403b9218a38962ab4e43021b93585
  51. 51. [Token]
  52. 52. #wpsummit @randyhoyt@randyhoyt•Does it have tobe real time?•What if somethinggoes wrong?API Questions
  53. 53. [Refresh Button]
  54. 54. WordPress Functions
  55. 55. WordPress wp_ajax, http://trhou.se/wp_ajax_hook
  56. 56. GET  Request  with  WordPress  HTTP  APIWordPress HTTP API, http://codex.wordpress.org/HTTP_API
  57. 57. WordPress update_option, http://trhou.se/update_option
  58. 58. Transients?WordPress, http://codex.wordpress.org/Transients_API
  59. 59. TLC Transientshttp://github.com/markjaquith/WP-TLC-Transients
  60. 60. Integrating WordPressWith Web APIsRandy Hoyt randyhoyt.com@randyhoytPresentation randyhoyt.com/wpsummit13
  61. 61. [Screenshot of Cultivatr]
  62. 62. [Screenshot of Edit Screen]
  63. 63. [Screenshot of Date Picker]
  64. 64. [Diagram]
  65. 65. @randyhoyt•Does it have tobe real time?•What if somethinggoes wrong?API Questions
  66. 66. @randyhoyt• GET• POST• PUT• DELETEREST: Types of Requests(Read)(Create)(Update)(Delete)
  67. 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. 68. Integrating WordPressWith Web APIsRandy Hoyt randyhoyt.com@randyhoytPresentation randyhoyt.com/wpsummit13

×