OpenSocial Network Programming Lynne Grewe WILEY Wiley Publishing, Inc.
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
Longer Engagement 39 Use of Media 39 Internationalization 41 Self Expression 43 Partnering 43 Virtual Currencies, Goods, and Points 43 Mobile Applications 45 Increased Use of Social Data 45 Increased Use of Application Data 46 Viral Channels and Features 46 Social Network Identity 48 Marketing The Next Step 50 Retention 53 Tips for Good Application Development 53 Summary 54 Chapter 2: Introduction to OpenSocial 57 OpenSocial History 57 OpenSocial Architecture 59 Client-Based API 60 Server-Based API 61 Application Architecture 65 Sample Application 66 OpenSocial Data Formats 67 JSON 67 Atom 68 XML 68 Application Deployment 69 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 85 Summary 88 Chapter 3: Gadget XML and Gadget API 89 Gadget XML 89 Gadget API 97 x
Core Gadget API 97 Feature-Specific Gadget API 104 Multiple Views 109 Changing Views Dynamically 111 Lifecycle Support 111 Summary 112 Chapter 4: JavaScript API 113 A Simple Application in OpenSocial 113 OpenSocial API Features 117 People 118 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 141 Information Storage 142 Information Retrieval 142 Detail of OpenSocial JavaScript API 146 Summary 170 Chapter 5: OpenSocial RESTful API 169 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 XI
НИР 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 198 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 212 HTTP Status Codes 213 OpenSocial REST Support Discovery 213 OpenSocial Security with the REST API 216 OpenSocial REST API Future 216 OpenSocial RPC Protocol 216 Summary 219 Chapter 6: Programming Fundamentals 223 Application Testing 223 Front-End GUI Design Tips 224 Navigation Tabs, 224 Look and Feel 226 Social Network-Specific Looks 227 External Resources 228 Caching Issues 230 POST Request 231 Signed Request 232 Performance Improvement Using Preload 234 Capabilities Inquiry 234 Action Requests and Permissions 234 Summary 235 Chapter 7: Sample Applications 235 Person/People Applications 235 Requesting a Maximum Number of Friends 236 Using Multiple Requests for Friends 236 Requesting Only Friends Who Have the Application Installed 237 XII
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 258 Understanding Environment Support and Domain 259 Handling Errors 262 Container Compliance and NOTJMPLEMENTED 262 Checking and Asking for Permissions 263 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 271 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 275 Chapter 8: Performance, Scalability, and Monetization 279 Understanding Scalability and Performance 280 Defining Scalability 280 Using Scalability Metrics 281 Performance Problem Areas 282 Scaling Up or Out 282 Understanding Architecture 282 Understanding Subsystems 284 Web Server 285 Application Server 285 xiii
Load Balancing 286 Caching 286 Content Delivery Networks (CDNs) 292 Understanding Hosting Solutions 292 What They're Saying about Hosting Solutions 294 Amazon Web Services (AWS) 294 Joyent 300 Other Hosting Solutions 301 Case Studies 301 Understanding Database Issues 302 Distributed Systems (Scale Out) 303 Database Sharding 303 Understanding Redundancy 304 Using Monitoring 304 Understanding Software Design 305 Language Choice 307 Versioning 307 OpenSocial Performance Tuning 308 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 314 Google Analytics 315 Yahoo! Web Analytics 317 Sometrics 318 Social Network-Provided 318 Using Scalable User Interface Design 318 Making the Most of User/System Support 319 XIV
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 325 Chapter 9: OpenSocial Templates, Markup, and Emerging Technologies 325 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 352 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 XV
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 374 Index 375 xvi