Table Of ContentBuilding
OpenSocial Apps
Developer’s Library Series
Visit developers-library.com for a complete list of available products
The Developer’s Library Series from Addison-Wesley provides
practicing programmers with unique, high-quality references and
tutorials on the latest programming languages and technologies they
use in their daily work. All books in the Developer’s Library are written by
expert technology practitioners who are exceptionally skilled at organizing
and presenting information in a way that’s useful for other programmers.
Developer’s Library books cover a wide range of topics, from open-
source programming languages and databases, Linux programming,
Microsoft, and Java, to Web development, social networking platforms,
Mac/iPhone programming, and Android programming.
Building
OpenSocial Apps
A Field Guide to Working with the
MySpace Platform
Chris Cole
Chad Russell
Jessica Whyte
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products Editor-in-Chief
are claimed as trademarks. Where those designations appear in this book,and the Mark L. Taub
publisher was aware of a trademark claim,the designations have been printed with initial
Acquisitions Editor
capital letters or in all capitals.
Trina MacDonald
The screenshots and other depictions of myspace.com contained in this book may not Development
accurately represent myspace.com as it exists today or in the future,including without Editor
limitation with respect to any policies,technical specs or product design. Songlin Qiu
The authors and publisher have taken care in the preparation of this book,but make no Managing Editor
expressed or implied warranty of any kind and assume no responsibility for errors or John Fuller
omissions. No liability is assumed for incidental or consequential damages in connection
Full-Service
with or arising out of the use of the information or programs contained herein.
Production
The publisher offers excellent discounts on this book when ordered in quantity for bulk Manager
purchases or special sales,which may include electronic versions and/or custom covers Julie B. Nahil
and content particular to your business,training goals,marketing focus,and branding Project
interests. For more information,please contact: Management
diacriTech LLC
U.S. Corporate and Government Sales
(800) 382-3419 Copy Editor
corpsales@pearsontechgroup.com Barbara Wood
For sales outside the United States,please contact: Indexer
Jack Lewis
International Sales
Proofreader
international@pearson.com
George Seki
Visit us on the Web: informit.com/aw
Technical
Library of Congress Cataloging-in-Publication Data Reviewers
Cassie Doll
Cole,Chris,1974- Bess Ho
Building OpenSocial apps : a field guide to working with the Benjamin Schupak
MySpace platform/Chris Cole,Chad Russell,Jessica Whyte.
Book Designer
p. cm.
Includes bibliographical references and index. Gary Adair
ISBN-13: 978-0-321-61906-8 (pbk. : alk. paper) Compositor
ISBN-10: 0-321-61906-4 (pbk. : alk. paper) diacriTech LLC
1. Entertainment computing. 2. Internet programming.3. MySpace.com. 4. OpenSocial.
5. Web site development. 6. Social networks—Computer network resources.
7. Application program interfaces (Computer software) I. Russell,Chad. II. Whyte,Jessica. III. Title.
QA76.9.E57C65 2010
006.7'54—dc22
2009032342
Copyright © 2010 Pearson Education,Inc.
All rights reserved. Printed in the United States of America. This publication is protected by
copyright,and permission must be obtained from the publisher prior to any prohibited
reproduction,storage in a retrieval system,or transmission in any form or by any means,
electronic,mechanical,photocopying,recording,or likewise. For information regarding
permissions,write to:
Pearson Education,Inc
Rights and Contracts Department
501 Boylston Street,Suite 900
Boston,MA 02116
Fax: (617) 671-3447
ISBN-13: 978-0-321-61906-8
ISBN-10: 0-321-61906-4
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville,Indiana.
First printing,October 2009
❖
This book is dedicated to my
ever-suffering wife,Kristen,and our two
crazy and wonderful children,Darien and
Reece.Thanks for working overtime with
the kids,baby
.
—Chris Cole
To the reader,we hope this book
serves you well.
—Chad Russell and Jessica Whyte
❖
Contents at a Glance
Contents viii
Foreword xvi
Acknowledgments xviii
About the Authors xix
Introduction xxi
I: Building Your First MySpace Application
1 Your First MySpace App 3
2 Getting Basic MySpace Data 9
3 Getting Additional MySpace Data 29
4 Persisting Information 47
5 Communication and Viral Features 67
6 Mashups and External Server
Communications 91
7 Flushing and Fleshing: Expanding Your
App and Person-to-Person Game Play 117
II: Other Ways to Build Apps
8 OAuth and Phoning Home 153
9 External Iframe Apps 177
10 OSML,Gadgets,and the Data Pipeline 213
11 Advanced OSML: Templates,Internationalization,
and View Navigation 239
III: Growth and How to Deal with It
12 App Life Cycle 265
13 Performance,Scaling,and Security 283
Contents at a Glance vviiii
14 Marketing and Monetizing 305
15 Porting Your App to OpenSocial 0.9 329
References 351
Index 355
Contents
Foreword xvi
Acknowledgments xviii
About the Authors xix
Introduction xxi
I: Building Your First MySpace Application
1 Your First MySpace App 3
Creating the App—“Hello World” 3
Step 1: Sign Up for a Developer Account 3
Step 2: Create an App 4
Step 3: Enter Your Source Code 4
Installing and Running Your App 7
Summary 7
2 Getting Basic MySpace Data 9
The Two Concepts That Every Developer
Should Know 9
Basic Concepts: Owner and Viewer 9
Basic Concepts: Permissions for Accessing
MySpace Data 10
Starting Our Tic-Tac-Toe App 10
Accessing MySpace User Data 11
Accessing Profile Information Using the
opensocial.Person Object 15
Getting More than Just the Default Profile Data 18
opensocial.DataResponse and opensocial.
ResponseItem (aka,Using MySpace User Data) 19
Error Handling 24
Summary 27
3 Getting Additional MySpace Data 29
How to Fetch a Friend List and Make Use of
the Data 29
Getting the Friend List 30
Filters and Sorts 31
Contents ix
Paging 32
Using the Data 37
Fetching Media 39
Photos 39
Albums and Videos 41
Using opensocial.requestPermission and
opensocial.hasPermission to Check a User’s
Permission Settings 43
Summary 45
4 Persisting Information 47
App Data Store 47
Saving and Retrieving Data 48
Refactoring to Build a Local App Data Store 51
Cookies 56
Why You Shouldn’t Use Cookies 57
Building the Cookie Jacker App 59
Third-Party Database Storage 64
Summary 65
5 Communication and Viral Features 67
Using opensocial.requestShareApp to Spread Your App to
Other Users 67
Defining requestShareApp 70
Writing the requestShareApp Code 71
Calling requestShareApp 72
The requestShareApp Callback 72
Using opensocial.requestSendMessage to Send Messages
and Communications 74
Defining requestSendMessage 75
Writing the requestSendMessage Code 76
Callback in requestSendMessage 78
Getting Your App Listed on the Friend Updates with
opensocial.requestCreateActivity Basics 79
Defining opensocial.requestCreateActivity 79
Using the Template System to Create Activities 80
Data Types 80
Reserved Variable Names 81
Aggregation 82