OpenSocial™
Network Programming
Lynne Grewe
WILEY
Introduction xvii
Chapter 1 : Social Network Programming 1
Social Network Platforms 2
MySpace 2 hi5 5 orkut 7 Friendster 8 imeem 9 Freebar 9 Netlog 11 Yahoo! 12 Other Networks 14
Social Network Applications 14
Application Discovery 15 Application Installation 16 Application Appearance 17 Control of Applications 25
Making Applications Social and Viral 29
Application Goals 29
Growth 30 Engagement 30 Good Look and Feel 32 Dynamic Evolution 32 Seif Expression 32 Social Exposure 33 Relationship Building 33 Real-World Problem Solving 33
Application Trends 33
Reach (General Appeal) Applications 35 Vertical (Targeted) Applications 36 Template-Based Application Development 36
Brand Applications 39 Destination Applications 39
Contents
Longer Engagement 39 Use of Media 39 Internationalization 4 1 Self Expression 43 Partnering 43 Virtual Currencies, Goods, and Points 43Mobile Applications 45 Increased Use of Social Data 45
Increased Use of Application Data 46
Viral Channels and Features 4 6 Social Network Identity 4 8 Marketing — The Next Step 50
Retention 53 Tips for Good Application Development 53
Summary 54 Chapter 2 : Introduction to OpenSocial 5 7
OpenSocial History 57 OpenSocial Architecture 59 Client-Based API 60 Server-Based API 61 Application Architecture 6 5 Sample Application 6 6 OpenSocial Data Formats 67
JSON 67 Atom 68 XML 68 Application Deployment 6 9 MySpace Deployment 69 hi5 Deployment 76 orkut Deployment 77 Netlog Deployment 80 imeem Deployment 80 Friendster Deployment 82 Freebar Deployment 85
What You Need to Get Started 8 5
Summary 8 8 Chapter 3 : Gadget X M L and Gadget API 8 9
Gadget XML 89 Gadget API 9 7
Core Gadget API 97 Feature-Specific Gadget API 104
Multiple Views 109
Changing Views Dynamically 111
Lifecycle Support 1 1 1
Summary 112 Chapter 4 : JavaScript API 1 1 3
A Simple Application in OpenSocial 113
OpenSocial API Features 117
People 1 1 8 ViewerData Example 119 GetFriends Example 121 Info Example 124 IdSpec 124 Activities 132
Messages — Email and Notifications 133
Activity Posting (Updates) 136 Invitations to Install 139
Persistence 1 4 1
Information Storage 142 Information Retrieval 142
Detail of OpenSocial JavaScript API 1 4 6
Summary 170 Chapter 5: OpenSocial RESTful API 1 6 9
Getting to Know REST 169
Purely RESTful Architecture 171 RESTful-RPC Hybrid Architecture 171 Looking at an Example of REST 171
OpenSocial RESTful Server-Side Programming 173
Completely Server-Based OpenSocial RESTful API Application 173 Hybrid OpenSocial JavaScript and RESTful API Application 175
OpenSocial RESTful Application Architecture 175 OpenSocial REST Authorization and Authentication (OAuth) 176
OAuth Steps 177 OAuth Parameters 179 OAuth Requests 179 OAuth Signing Requests 180 OAuth Tokens (the Response) 181
OAuth in PHP 181
Contents
НИР Errors 195 OpenID 195 Key Cache and Token Management 195
OAuth Libraries 196 What You Need 196 hi5 Authentication Scheme 196
OpenSocial RESTful API Details 1 9 8
OpenSocial REST Request Construction 198 OpenSocial REST API Specification 200 Data Formatting and Atom/AtomPub 203
HTTP Method Type 210 OpenSocial REST Response 211
What You Need 212
OpenSocial REST Application Deployment 2 1 2
HTTP Status Codes 2 1 3 OpenSocial REST Support Discovery 2 1 3
OpenSocial Security with the REST API 216
OpenSocial REST API Future 2 1 6 OpenSocial RPC Protocol 2 1 6
Summary 2 1 9 Chapter 6: Programming Fundamentals 2 2 3
Application Testing 2 2 3 Front-End GUI Design Tips 2 2 4
Navigation Tabs , 224
Look and Feel 226 Social Network-Specific Looks 227
External Resources 2 2 8
Caching Issues 230 POST Request 231 Signed Request 232 Performance Improvement Using Preload 234
Capabilities Inquiry 234 Action Requests and Permissions 234
Summary 2 3 5 Chapter 7: Sample Applications 2 3 5
Person/People Applications 2 3 5
Requesting a Maximum Number of Friends 236 Using Multiple Requests for Friends 236 Requesting Only Friends Who Have the Application Installed 237
Producing a Paginated Friends List 238
Using Pronouns 239 Creating a Friend Selector 241
Testing If Two Users Are Friends 243 Finding Top Friends Who Have the Application Installed 244
Friends of Friends 246
Communications Applications 246
Making Signed Requests 247 Creating Minimessages 249 Creating Gadget Message Bundles 250
Using Message and Activity Templates 251
Using Message Summaries 254 Using Media Items in Activities 254
Clearing AppData 2 5 8 Understanding Environment — Support and Domain 2 5 9
Handling Errors 2 6 2
Container Compliance and NOTJMPLEMENTED 262
Checking and Asking for Permissions 2 6 3 Working with Container-Specific Extensions 264
hi5 Lifecycle Extension 265 DataRequest Extension 266 Fields Extension 266 hi5 Template Library 266
Using Internationalization, Localization, and Globalization 267
Using Flash Media 2 7 1
Option 1: Using the Gadget API 271 Option 2: Using the SWFObject JavaScript Library 272
More Configuration Options 273
Container Support 274
JavaScript Tools for Applications 274
Summary 2 7 5 Chapter 8 : Performance, Scalability, and Monetization 2 7 9
Understanding Scalability and Performance 280
Defining Scalability 280 Using Scalability Metrics 281 Performance Problem Areas 282
Scaling Up or Out 282 Understanding Architecture 2 8 2 Understanding Subsystems 284 Web Server 285 Application Server 285 xiii
Contents
Load Balancing 286 Caching 286 Content Delivery Networks (CDNs) 292
Understanding Hosting Solutions 2 9 2
What They're Saying about Hosting Solutions 294
Amazon Web Services (AWS) 294
Joyent 300 Other Hosting Solutions 301
Case Studies 3 0 1 Understanding Database Issues 3 0 2
Distributed Systems (Scale Out) 303
Database Sharding 303
Understanding Redundancy 3 0 4
Using Monitoring 3 0 4 Understanding Software Design 3 0 5
Language Choice 307 Versioning 307
OpenSocial Performance Tuning 3 0 8
Minimizing the Number of HTTP Requests 308
Batching Multiple Requests 308 Using OpenSocial AppData as a Container Cache 309
Reducing the Number of DNS Lookups 309
Reducing the Number of Files 309 Turning on the Persistence Feature in a Web Server 309
Compressing Content Using GZIP 310
"Minifying" JavaScript 310 Using CSS in a Header 310 Locating JavaScript at the Bottom 311
Caching versus Requests for External Files (JavaScript, CSS) 311
Flushing a Server Response 311 Monitoring Client Code Performance 311
Preloading OpenSocial Content 313 Achieving Good Load Times 314 Using OpenSocial get from Cache 314
Using CSS Image Sprites 314
Using Analytics 3 1 4
Google Analytics 315 Yahoo! Web Analytics 317
Sometrics 318 Social Network-Provided 318
Using Scalable User Interface Design 3 1 8 Making the Most of User/System Support 3 1 9
Monetization 320
Advertising 320 Affiliate Programs 321 Partnering 322 Virtual Goods and Virtual Currency 322
Real Goods and Micropayments/Micro-Transactions 323
Monetization Case Studies 323
Summary 3 2 5
Chapter 9: OpenSocial Templates, Markup, and Emerging Technologies 3 2 5
OpenSocial Templates Standard 325
Requiring a Feature 326 Understanding Basic Template Construction and Use 327
Naming Templates 328 Using Expressions in Templates 329
Using Variables and Passing Data to a Template 330
Calling Templates with Parameters 331 Using the repeat Attribute for Looping 332
Using Conditional Tests 332 Localization with Templates 332 Using a Separate Definition File for Templates 333
OpenSocial Markup Language 334 OpenSocial Data Pipelining 345 OpenSocial Template Examples 350
OpenSocial Proxied Content 3 5 2 OpenSocial Client Libraries 353 Yahoo! Open Strategy 353
Y!OS Architecture 354 Yahoo! User Profiles 355 Yahoo! User Updates 355 Yahoo! Applications (YAP) 356 YAP Application Development Steps 360
YAP OpenSocial Application Development 361
Yahoo! Query Language 364 Understanding the Yahoo! User Interface (YUI) 365
Using Yahoo! Markup Language (YML) 365
Y!OS Application Examples 366
iWidgets 367 Zembly 368
Understanding the Zembly Application Structure 369
Understanding a Zembly Service 370 Understanding a Zembly Widget 371
Contents
Understanding a Zembiy Snippet 371 Understanding a Zembiy Key Chain 371 Creating an OpenSocial Application in Zembiy 371
Publishing an Application 373 Creating Your Own Service 373
Summary 3 7 4