Building OpenSocial Apps- P5

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:50

0
47
lượt xem
5
download

Building OpenSocial Apps- P5

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Building OpenSocial Apps- P5: Nhà phát triển của Thư viện Series từ Addison-Wesley cung cấp hành nghề lập trình với độc đáo, tài liệu tham khảo chất lượng cao hướ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ởi chuyê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ức và 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....

Chủ đề:
Lưu

Nội dung Text: Building OpenSocial Apps- P5

  1. 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 spare Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  2. 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.
  3. This page intentionally left blank Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  4. 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 rendering of the app. Off-site apps behave much more like traditional Web pages. A request comes in, then it’s picked up by your Web server and passed off for processing to your scripting language of choice, such as PHP, ASP.NET, or Python. The request is then processed. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  5. 178 Chapter 9 External Iframe Apps Let’s say we send off a REST request to the MySpace API for a friend list and also pull some data out of our local database. The friend list and the data are then pushed down onto the page used as the iframe app. In this case, the app has all the data it needs to fully load at render time. The trade-off here is that on-site apps render immediately, then idle while waiting for data. Off-site apps, by contrast, do their waiting for data up front and then completely load. The other big difference is that with on on-site apps you really have only one page. In our Tic-Tac-Toe app we hide and show various HTML elements to give the illusion of multiple pages. Off-site apps can have multiple actual pages, so markup and JavaScript code can be separated a little more cleanly.Well-known techniques like clicking a button that posts back a form can be used. As you can see, there are some pros and cons to using an off-site app.The biggest reason for using one would be that you have an existing app somewhere on the Web that you could wrap an iframe around and there you go—you now have an instant MySpace app. So, let’s dig a little deeper into what it would take to accomplish that. REST APIs What exactly is a “REST API”? Well, REST stands for REpresentational State Transfer, which isn’t overly helpful as an actual definition. It essentially comes down to how resources are accessed. The underlying assumption with REST is that objects and records exist in one place, their universal resource identifier (URI), on the Internet and stay there.The address is used to state the “who” of the object we wish to work with. This is coupled with an action verb (for example, GET or POST) in the request to state the “what” of what we wish to do. How a REST Web Service Is Addressed A REST Web service is addressed via URIs. Say we have a REST Web service that returns data on fruit.To get a list of all the fruit available, we might access a URI like this with a GET request: http://fakefruitsite.com/fruit Let’s say that Web service returns a list of available fruit, and one of the fruits listed is apple. We might make a call like this to get a list of the types of apples available: http://fakefruitsite.com/fruit/apple Specifically, we might want to know which local producers grow Granny Smith apples: http://fakefruitsite.com/fruit/apple/grannysmith/producers And even more specifically, there’s an orchard down the street that we want data on. Each producer would have a unique identifier; this one’s is 12345. We might access the price list for that producer’s Granny Smiths via the following URI: http://fakefruitsite.com/fruit/apple/grannysmith/producers/12345/pricelist Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  6. REST APIs 179 This is an example of a REST API; we access the actual data we want by addressing the URI in a specific way and use a globally unique identifier (GUID) to drill down to specific entities. MySpace’s APIs follow a similar pattern but replace fruit with MySpace users, GUIDs with MySpace IDs, and price lists with friend lists. If you are not used to using REST, this may seem a little strange and low-level, but MySpace provides several SDKs to help you out.The beauty of having an SDK is that just about all of this is abstracted away. You’ll see shortly how easy it is to make requests to the MySpace APIs using an SDK. Setting Up an External Iframe App Now that we understand what the REST APIs are, let’s take a look at how to set up an app on MySpace that will make use of them. Up until now, our Tic-Tac-Toe app has used MySpace’s OpenSocial container to make requests to the API, has lived on MySpace servers, and has been written entirely in JavaScript. What if we had an app already written and running on a Web site and wanted to make it a MySpace app? Would we have to completely rewrite the app in JavaScript? And convert all of our server communication to makeRequest? That’s one possibility, but another is to simply “iframe your app.” What that means is that MySpace provides the ability to load in an external iframe on the Canvas surface instead of loading in the usual MySpace-hosted iframe. Let’s walk through what it might take to convert parts of our Tic-Tac-Toe app to an iframe app. First we’ll need to create a new app by following the instructions found in Chapter 1, Your First MySpace App. Once it’s created, navigate to Edit App Source and click on the Canvas Surface tab (it’s the default tab). Instead of selecting HTML/Javascript Source from the radio buttons at the top, we’ll select External Iframe. Then, inside the External IFrame URL field, enter the starting point for your app. In our case, and as shown in Figure 9.1, it’s http://opensocial—tic-tac-toe.appspot.com/play. When the Canvas surface for this app loads, it will load the page you entered into the External Iframe URL field instead of loading a MySpace-hosted page. In addition, it will append several parameters to the source of the iframe in order to pass values to your app. An example of this would be the following: http://opensocial—tic-tac-toe.appspot.com/play? appid=131583& country=us& installState=1& lang=en& oauth_consumer_key=http%3A%2F%2Fwww.myspace.com%2F461572677& oauth_nonce=633738729982017828& oauth_signature=11LDA8y%2FTsE36vg%2BKXKfSxJrkok%3D& oauth_signature_method=HMAC-SHA1& oauth_timestamp=1238276198& oauth_version=1.0& Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  7. 180 Chapter 9 External Iframe Apps Figure 9.1 Screen shot of the external iframe URL setup process. opensocial_owner_id=183399670& opensocial_surface=canvas& opensocial_token=H1YEBkwWjVWJLEo7n%2FVFM%2FDl1uvHTAVVfubkLWHNF1a4k9h1D6PCyLaNzTkFJ ➥AOCaxGIlluygnH2d4tuLcfbQnxbgNMN2%2FnPqp2sCZDCXt0%3D& opensocial_viewer_id=183399670& perm=%5B%22UT%22%2C%22UF%22%2C%22RN%22%2C%22PB%22%2C%22SN%22%2C%22%22%2C%22BI%22% ➥5D& ptoString=COMMENTS%2CBLOG%2CBULLETINS%2CPROFILE%2CSEND_MESSAGE%2CSHARE_APP%2C ➥ACTIVITY As you can see, our base URL, http://opensocial—tic-tac-toe.appspot.com/play, has several query string parameters appended to it. There are some session-specific values, such as the language and country of the current user, the user ID, and whether the user has the app installed.The app’s ID and OAuth parameters are also passed down.This allows you to verify the request in the same way we verified a signed makeRequest in Chapter 8, Oauth and Phoning Home; essentially the iframe URL becomes an authenti- cated OAuth request. We’ll discuss the opensocial_token, perm, and ptoString parameters later in the chapter when we discuss cross-domain communication and sending messages. When our initial page loads, we’ll be able to determine the user’s ID, use the MySpace SDK to fetch any data we might need from the MySpace APIs, and push the data onto the page when it renders. Let’s implement the Play and Invite tabs of our current Tic-Tac-Toe app.The Play tab requires the user’s Profile data, and the Invite tab requires the user’s friend list. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  8. REST APIs 181 The Server Code Let’s go back to our code from Chapter 8 and update our app.yaml again. For reference, you can find the Chapter 8 code in this folder: http://opensocialtictactoe.googlecode.com/svn/trunk/chapter8/opensocial—tic-tac-toe/. application: opensocial—tic-tac-toe version: 1 runtime: python api_version: 1 handlers: - url: /ws script: ws/ws.py - url: /play script: play/play.py - url: /invite script: invite/invite.py As you can see, we’re going to use two separate pages for the two tabs. The handlers for each (play.py and invite.py) are very similar. Let’s take a look at invite.py in detail and then take a quick look at play.py. import os import ckeynsecret from django.utils import simplejson from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.webapp import template from myspace.myspaceapi import MySpace, MySpaceError from oauthlib import oauth from entities import WinLoss class Invite(webapp.RequestHandler): def get(self): id = self.request.get(‘opensocial_viewer_id’) appid = self.request.get(‘appid’) opensocial_token = self.request.get(‘opensocial_token’) error = False Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  9. 182 Chapter 9 External Iframe Apps try: int(id) int(appid) except: error = True ms = MySpace(ckeynsecret.CONSUMER_KEY, ckeynsecret.CONSUMER_SECRET) ms.token = oauth.OAuthToken(‘’, ‘’) try: friends = ms.get_friends(id) except MySpaceError, mse: error = True if error: msg = ‘Oops, there was an error, try refreshing the page!’ self.response.out.write(msg) return json = simplejson.dumps(friends) if json is None: json = ‘{}’ template_values = { ‘friends_obj’: json, ‘appid’: appid, ‘ownerId’: id, ‘opensocial_token’: opensocial_token } path = os.path.join(os.path.dirname(__file__), ‘invite.html’) self.response.out.write(template.render(path, template_values)) application = webapp.WSGIApplication( [(‘/invite’, Invite)], debug=True) def main(): run_wsgi_app(application) if __name__ == “__main__”: main() import ckeynsecret includes our consumer key and secret from an external file, and we import the official MySpace SDK using from myspace.myspaceapi import MySpace, MySpaceError. For the request handler itself, we define only a GET handler. Just as in our Chapter 8 code, it starts by checking the incoming user ID and app ID to make sure they’re integers. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  10. REST APIs 183 To make use of the MySpace SDK (you can download it at http://code.google.com/p/myspaceid-sdk/ and pick the language of your choice), we need to instantiate a MySpace object. All of the API functionality will be done through this object. To initialize the MySpace object, you need to always do the following two things: ms = MySpace(ckeynsecret.CONSUMER_KEY, ckeynsecret.CONSUMER_SECRET) ms.token = oauth.OAuthToken('', '') The first line creates the MySpace object given the consumer key and secret.The second creates an OAuth token; the two parameters are always empty strings when accessing the MySpace API with an OpenSocial app. Fetching a friend list is as simple as this: friends = ms.get_friends(id) That’s all there is to it; the SDK should take care of the rest. Assuming no exception was thrown, we now have the user’s friend list.The circumstances for throwing an exception are mostly permission-related—the user might not have the app installed, might be blocking the app, and so on. We then get the friend list ready to be pushed down onto the page by using simplejson.dumps(friends). We pass a total of four items down to the page: the friend list, the app ID, the owner ID, and the OpenSocial token. REST API List Now that we’ve seen one of the APIs in action, let’s take a look at what other functionality the SDKs support. Table 9.1 describes all of the endpoints supported by the MySpace SDK as of this writing. Some of the data has been truncated for readability, but these are mostly just long URLs. The most important part, the schema of the data, is intact. MySpace also maintains documentation for the APIs (not the SDKs themselves, just the bare endpoints) at http://wiki.developer.myspace.com/index. php?title=MySpace_REST_Resources. Table 9.1 Overview of Endpoints Supported by the MySpace SDK Function name get_albums Description Fetches a list of albums Parameters user_id—the ID of the user Sample response { "count": 1, "albums": Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  11. 184 Chapter 9 External Iframe Apps Table 9.1 Continued [{ "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "photoCount": 1, "photosUri": "http:\/\/uri_to_photos", "privacy": "Everyone", "defaultImage": "http:\/\/path_to_img.jpg", "title": "My Photos", "location": "", "id": 542074, "albumUri": "http:\/\/uri_to_album" }], "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} } Function name get_album Description Fetches data for a particular album Parameters user_id—the ID of the user album_id—the ID of the album Sample response { "count": 1, "photos": [{ "photoUri": "http:\/\/uri_to_photo", Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  12. REST APIs 185 Table 9.1 Continued "smallImageUri": "http:\/\/path_to_img.jpg", "caption": "", "uploadDate": "4\/25\/2007 12:56:26 PM", "lastUpdatedDate": "", "imageUri": "http:\/\/path_to_img.jpg", "id": 1982932, "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} }], "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} } Function name get_friends Description Fetches a list of friends Parameters user_id—the ID of the user page—the page number page_size—the number of records to fetch list—defines how to filter the friend list; one of the following values can be provided: top—only the top friends online—only friends who are currently online app—only friends who have the app installed show—what extra data to provide for each friend; any combination of the following values is allowed: mood—each friend’s mood Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  13. 186 Chapter 9 External Iframe Apps Table 9.1 Continued status—each friend’s status online—whether or not each friend is online Sample response { "count": 2, "Friends": [ {"name": "Tom", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 6221, "uri": "http:\/\/api.myspace.com\/v1\/users\/6221", "webUri": "http:\/\/www.myspace.com\/tom", "userType": "RegularUser"}, {"name": "Chris Cole", "largeImage": "http:\/\/path_to_img.png", "image": "http:\/\/path_to_img.png", "userId": 45070236, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/45070236", "webUri": "http:\/\/www.myspace.com\/ccole_myspace", "userType": "RegularUser"} ], "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "topFriends": "http:\/\/uri_to_topfriends", "next": "http:\/\/uri_to_next" } Notes The "next" URI is to aid in paging; it returns the URI to use to retrieve the next page of friends. But since we’re using the SDK and not manually sending out these requests, we’ll have to maintain the Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  14. REST APIs 187 Table 9.1 Continued paging state the same way we did for the on-site app. An example URI is http://api.myspace.com/v1/users/183399670/friends.json? page=3&page_size=50. Function name get_friendship Description Given a user ID and a list of friend IDs, returns true for each ID in the list that is a friend of the user, false otherwise Parameters user_id—the ID of the user friend_ids—a semicolon-delimited list of integer IDs Sample response { "friendship": [{ "friendId": 6221, "areFriends": true }], "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} } Notes Either the MySpace SDK or the API has a bug with this endpoint. A semicolon-delimited list of friend IDs is required for the friend_ids parameter. The endpoint correctly returns data if you use just one ID, such as 6221. However, if you supply more than one ID, such as 6221;123456;876543, the API returns a 401 error. The error provided is “Invalid digital signature for base string.” Luckily, this endpoint isn’t the most useful. Function name get_mood Description Fetches the user’s mood data Parameters user_id—the ID of the user Sample response { "moodLastUpdated": "4\/12\/2009 8:32:10 PM", Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  15. 188 Chapter 9 External Iframe Apps Table 9.1 Continued "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "moodId": 56, "mood": "curious", "moodImageUrl": "http:\/\/x.myspacecdn.com\/images\/blog\/moods\/ ➥iBrads\/curious.gif" } Function name get_moods Description Fetches the entire list of moods currently supported by MySpace for the particular user Parameters user_id—the ID of the user Sample response { "moods": [ { "moodName": "accomplished", "moodPictureUrl": "http:\/\/path_to_img.gif", "moodId": 90, "moodPictureName": "chipper.gif" }, { "moodName": "adored", "moodPictureUrl": "http:\/\/path_to_img.gif", "moodId": 135, "moodPictureName": "adored.gif" } ] } Function name get_photos Description Fetches a list of photos Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  16. REST APIs 189 Table 9.1 Continued Parameters user_id—the ID of the user page—the page number page_size—the number of records to fetch Sample response { "count": 2, "photos": [ {"photoUri": "http:\/\/uri_to_photo", "smallImageUri": "http:\/\/path_to_img.jpg", "caption": "", "uploadDate": "4\/25\/2007 12:56:26 PM", "lastUpdatedDate": "", "imageUri": "http:\/\/path_to_img.jpg", "id": 1982932, "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} }, {"photoUri": "http:\/\/uri_to_photo", "smallImageUri": "http:\/\/path_to_img.jpg", "caption": "", "uploadDate": "9\/11\/2008 4:25:22 PM", "lastUpdatedDate": "", "imageUri": "http:\/\/path_to_img.jpg", "id": 26834127, "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  17. 190 Chapter 9 External Iframe Apps Table 9.1 Continued "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} }, ], "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} } Function name get_photo Description Fetches data on a particular photo Parameters user_id—the ID of the user photo_id—the ID of the photo Sample response { "photoUri": "http:\/\/uri_to_photo", "smallImageUri": "http:\/\/path_to_img.jpg", "caption": "", "uploadDate": "4\/25\/2007 12:56:26 PM", "lastUpdatedDate": "", "imageUri": "http:\/\/path_to_img.jpg", "id": 1982932, "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"} } Function name get_profile Description Fetches Profile data Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  18. REST APIs 191 Table 9.1 Continued Parameters user_id—the ID of the user type—the level of detail to fetch for the Profile data; valid values are basic, full, and extended Sample response { "name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "lastUpdatedDate": "1\/1\/2009 2:11:28 PM", "type": "basic" } Notes Later in the chapter we’ll discuss the differences among the three levels of detail. The sample response here is for a basic Profile; we’ll make use of an extended Profile a little later. Function name get_status Description Fetches the user’s status and mood Parameters user_id—the ID of the user Sample response { "status": "is testing", "mood": "curious", "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "moodLastUpdated": "4\/12\/2009 8:32:10 PM", "moodId": 56, "moodImageUrl": "http:\/\/x.myspacecdn.com\/images\/blog\/moods\ ➥/iBrads\/curious.gif" } Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  19. 192 Chapter 9 External Iframe Apps Table 9.1 Continued Function name get_videos Description Fetches a list of videos Parameters user_id—the ID of the user Sample response { "count": 1, "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "videos": [{ "mediastatus": "ProcessingSuccessful", "description": "Not a whole lot...", "language": "en", "privacy": "Public", "country": "US", "totalviews": "0", "title": "Test Video", "totalrating": "0", "mediatype": "4", "datecreated": "1\/1\/2009 2:30:48 PM", "resourceuserid": "183399670", "thumbnail": "http:\/\/path_to_img.jpg", "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "totalcomments": "0", Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  20. REST APIs 193 Table 9.1 Continued "totalvotes": "0", "dateupdated": "1\/1\/2009 2:30:22 PM", "runtime": "0", "id": 55701156, "videoUri": "http:\/\/uri_to_video" }] } Function name get_video Description Fetches data for a particular video Parameters user_id—the ID of the user video_id—the ID of the video Sample response { "mediastatus": "ProcessingSuccessful", "description": "Not a whole lot...", "language": "en", "privacy": "Public", "country": "US", "totalviews": "0", "title": "Test Video", "totalrating": "0", "mediatype": "4", "datecreated": "1\/1\/2009 2:30:48 PM", "resourceuserid": "183399670", "thumbnail": "http:\/\/path_to_img.jpg", "user": {"name": "Chad Russell", "largeImage": "http:\/\/path_to_img.jpg", "image": "http:\/\/path_to_img.jpg", "userId": 183399670, "uri": ➥"http:\/\/api.myspace.com\/v1\/users\/183399670", "webUri": "http:\/\/www.myspace.com\/cdsrussell", "userType": "RegularUser"}, "totalcomments": "0", "totalvotes": "0", "dateupdated": "1\/1\/2009 2:30:22 PM", "runtime": "0", "id": 55701156, Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Đồng bộ tài khoản