Thông tin tài liệu:
Building OpenSocial Apps- P5: Nhà phát triển của Thư viện Series từ Addison-Wesley cung cấphành nghề lập trình với độc đáo, tài liệu tham khảo chất lượng caohướng dẫn về các ngôn ngữ lập trình công nghệ mới nhất và họsử dụng trong công việc hàng ngày của họ. Tất cả các sách trong thư viện của Nhà phát triển được viết bởichuyên gia công nghệ các học viên những người có kỹ năng đặc biệt tại các tổ chứcvà trình bày thông tin một cách đó là hữu ích cho các lập trình viên khác....
Nội dung trích xuất từ tài liệu:
Building OpenSocial Apps- P5 174 Chapter 8 OAuth and Phoning Home Figure 8.3 Example of Canvas surface link on a user’s Profile Summary Being able to communicate securely with an external server has some huge advantages. You can write custom Web services and host large databases.The possibilities are nearly limitless. There are many options out there for hosting providers.We chose Google App Engine mainly because it is free for sites with small amounts of traffic, and free is nice. Amazon Web Service (AWS) is a competing “cloud-computing” service that behaves differently from GAE.With GAE you’re forced to use their Web servers and database back end, write your code in Python or Java, and upload it all to their servers.With AWS you can pick and choose which of their services to use and in what language you write your code. There’s also Microsoft’s Azure, not to mention traditional Web hosting companies from which you can rent physical servers sitting in physical racks.There’s also that sparePlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Summary 175 computer you have sitting in your closet, but that probably can’t handle too many concurrent users (see Chapter 13, Performance, Scaling, and Security, to learn how to scale your app). Before deciding on a service, it’s best to shop around and do some research. See what’s easiest, and possibly cheapest, for your new app.Whatever you choose, use the basic principles outlined in this chapter to safely communicate between MySpace and your hosting service. Note Code listings and/or code examples for this chapter can be found on our Google Code page under http://opensocialtictactoe.googlecode.com.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. This page intentionally left blankPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 9 External Iframe Apps This chapter is of OAuth thatextension of thethis chapterone. In Chapter external essentially an preceding 8 we discussed several elements are relevant to and to writing iframe apps on the MySpace platform. We recommend that if you skipped Chapter 8, go back now and read the sections that describe OAuth. Moving forward in this chapter, we’ll assume you’re familiar with OAuth and with setting up and publishing Web services using Python on Google App Engine (GAE). In this chapter we’ll take our existing on-site app and port it over to an external iframe, or off-site, app. Be prepared, because there’s a pretty large paradigm shift from an on-site JavaScript app to an off-site app. With on-site apps, you supply some markup and possibly a few Web services, and the MySpace platform takes care of the rest.Your markup is wrapped in some headers and footers (mostly script tags that pull in the OpenSocial container) so it can be correctly rendered. When a user accesses the page, the MySpace infrastructure takes care of the actual rendering of the page. When the app starts running, it has very little knowledge of the user; it really knows only the IDs of both the Viewer and the Owner.That means that the app has to send out requests for data when it loads—maybe it requires a friend list, or some details from your servers.These asynchronous requests are sent out while the app idles, perhaps with a loading message and one of those “spinner” graphics twirling away to give the illusion of activity.When the requests come back, the app leaps into action, as it should now have all the data it needs to fully load. That’s the typical flow of an on-site app, but off-site apps have a very different pattern. For an off-site app, MySpace simply renders an iframe onto the page with the src attribute set to the URL of your choice. Since you control the contents of the URL, you have full control over the app. But this control comes at a cost; you are now responsible for the rende ...