Getting Basic MySpace Data in Applications
- The Two Concepts That Every Developer Should Know
- Starting Our Tic-Tac-Toe App
- Accessing MySpace User Data
- Error Handling
- Summary
In this chapter we'll start with a very basic version of the Tic-Tac-Toe application and then expand on it to include examples of how you might fetch a user's name, address, and gender. We'll then show you how to use that information in your application. On the way, we'll cover how MySpace and OpenSocial define an opensocial.Person object and how to use that information to enrich your application.
We'll also get to really play with our Tic-Tac-Toe game. This will be our example app, and over the course of the book we'll take you from a basic game to a fully functional and feature-rich application.
At each step along the way we'll teach you new methods and programming tricks for accessing and using the OpenSocial API. Code examples will be shown in full and then broken down into segments for further explanation, allowing you to zero in on a specific feature or trouble spot.
The Two Concepts That Every Developer Should Know
Before we begin, there are two basic concepts that every MySpace and OpenSocial app developer should know about:
- In the world of MySpace apps, everyone is either an Owner or a Viewer.
- The MySpace permission model is a complex and confusing beast that will likely leave you frustrated and angry.
On that note, let's get started!
Basic Concepts: Owner and Viewer
The concept of Owner and Viewer is central to OpenSocial, and it boils down to
- Owner= the MySpace user on whose surface the application is running
- Viewer= the MySpace user who is currently interacting with the application
Once you start accessing MySpace data, all the requests you make are made in the context of the Owner and the Viewer.
For example, let's say John has the app installed and Jane is viewing John's MySpace Profile. John is the Owner and Jane is the Viewer. Alternatively, if John is looking at the app on his own MySpace Profile, he is both the Owner and the Viewer.
When you request data, you'll be asking for information about either the Owner or the Viewer.
Basic Concepts: Permissions for Accessing MySpace Data
Not all user data is accessible to apps, and the data that is accessible is subject to a sometimes convoluted permission model. The key idea behind the MySpace permission model (dubbed Open Canvas) is that under certain circumstances an app can access a user's data even if that user hasn't installed the app. However, this access can happen only on the app's Canvas surface and not on the Home or Profile surfaces.
Under this model there are essentially three core questions used to determine whether an app can access a piece of data:
- Does the Viewer have the app installed?
- Is the Viewer logged in?
- Has the Viewer blocked the app?Blocking an app prevents any and all access to the Viewer's data.
Figure 2.1 is a quick reference chart for Open Canvas; remember, though, that these permissions can change. So stay on your toes and watch out for permission traps when accessing user data.
Figure 2.1. MySpace Open Canvas permission model for accessing user data.
Viewer has added the app |
Viewer hasn't added the app |
Viewer is logged out |
Viewer has blocked the app |
|
Basic Owner data * (Home) |
Yes |
Yes |
Yes |
Yes |
Basic Owner data * (Profile) |
Yes |
Yes |
Yes |
Yes |
Basic Owner data * (Canvas) |
Yes |
Yes |
Yes |
Yes |
Basic Viewer data * (Home) |
Yes |
No |
No |
No |
Basic Viewer data * (Profile) |
Yes |
No |
No |
No |
Basic Viewer data * (Canvas) |
Yes |
Yes |
No |
No |
Owner's friend list |
Yes |
Yes |
Yes |
Yes |
Viewer's friend list |
Yes |
No |
No |
No |
Owner's public media ** |
Yes |
Yes |
Yes |
Yes |
Viewer's public media ** |
Yes |
No |
No |
No |