ebook img

Sams Teach Yourself the Twitter API in 24 Hours PDF

353 Pages·2011·9.45 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Sams Teach Yourself the Twitter API in 24 Hours

Christopher Peri Ph.D. SamsTeachYourself Twitter API the 24 in Hours 800 East 96th Street,Indianapolis,Indiana46240USA Sams Teach Yourself the Twitter API in 24 Hours Associate Publisher Copyright © 2011 by Pearson Education,Inc. Mark Taub All rights reserved. No part of this book shall be reproduced,stored in a retrieval Signing Editor system,or transmitted by any means,electronic,mechanical,photocopying,recording, or otherwise,without written permission from the publisher. No patent liability is Trina MacDonald assumed with respect to the use of the information contained herein. Although every Development Editor precaution has been taken in the preparation of this book,the publisher and author Songlin Qiu assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. Managing Editor ISBN-13: 978-0-672-33110-7 Kristy Hart ISBN-10: 0-672-33110-1 Library of Congress Cataloging-in-Publication Data Project Editor Peri,Christopher A.,1964- Andy Beaster Sams teach yourself the Twitter API in 24 hours / Christopher A. Peri,Bess P. Ho. Copy Editor p. cm. Barbara Hacha Includes index. ISBN-13: 978-0-672-33110-7 (pbk. : alk. paper) Indexer ISBN-10: 0-672-33110-1 (pbk. : alk. paper) Erika Millen 1. Application program interfaces (Computer software) 2. Twitter. I. Ho,Bess P., 1967- II. Title. III. Title: Teach yourself the Twitter API in 24 hours. Proofreader QA76.76.A63P47 2011 Sarah Kearns 006.7’54—dc23 2011022576 Technical Editors Printed in the United States of America Doug Jones First Printing June 2011 Ronan Schwartz Trademarks Ben Schupak All terms mentioned in this book that are known to be trademarks or service marks Publishing Coordinator have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the Olivia Basegio validity of any trademark or service mark. Cover Designer Warning and Disclaimer Gary Adair Every effort has been made to make this book as complete and as accurate as possible,but no warranty or fitness is implied. The information provided is on an Composition “as is” basis. The authors and the publisher shall have neither liability nor responsi- Gloria Schurick bility to any person or entity with respect to any loss or damages arising from the information contained in this book. Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information,please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S.,please contact International Sales [email protected] Contents at a Glance . Preface................................................................................... xiii HOUR 1 What Is Twitter?......................................................................... 1 HOUR 2 Twitter Out of the Box................................................................ 11 HOUR 3 Key Issues to Consider When Developing Twitter Applications.......... 21 HOUR 4 Creating a Development Environment.......................................... 33 HOUR 5 Making Your First API Call......................................................... 49 HOUR 6 Building a Simple Twitter Reader................................................. 59 HOUR 7 Creating a Twitter API Framework............................................... 73 HOUR 8 Twitter OAuth.......................................................................... 81 HOUR 9 Building a Simple Twitter Client, Part I......................................... 95 HOUR 10 Building a Simple Twitter Client, Part II...................................... 105 HOUR 11 Expanding Our Client for More API Calls.................................... 113 HOUR 12 Direct Messages....................................................................... 125 HOUR 13 Lists...................................................................................... 135 HOUR 14 Favorites and User Methods ...................................................... 147 HOUR 15 Search................................................................................... 161 HOUR 16 Trends and GEO...................................................................... 177 HOUR 17 Friendships, Notification, Block, and Account Methods.................. 193 HOUR 18 Twitter Documentation............................................................. 205 HOUR 19 Streaming API........................................................................ 219 HOUR 20 FailWhale and the Future of the API........................................... 229 HOUR 21 Getting Started in Twitter Android Application............................. 241 HOUR 22 Building Android Applications with Twitter................................. 255 HOUR 23 Getting Started with Twitter Using iOS........................................ 279 HOUR 24 Building an iPhone and iPod Touch Application with Twitter......... 293 Index.................................................................................... 319 Table of Contents HOUR 1: What Is Twitter? 1 What Twitter Offers You ........................................................................ 1 A Brief History of Twitter—or Why 140 Characters?.................................... 2 Summary............................................................................................ 7 Q&A.................................................................................................. 8 HOUR 2: Twitter Out of the Box 11 What Twitter Offers You ...................................................................... 11 Registering Your Application ................................................................ 15 The Twitter Client .............................................................................. 16 Summary.......................................................................................... 18 Q&A ................................................................................................ 18 HOUR 3: Key Issues to Consider When Developing Twitter Applications 21 Types of Twitter Users.......................................................................... 21 Types of Twitter Applications................................................................ 25 Platform............................................................................................ 30 Summary.......................................................................................... 31 Q&A ................................................................................................ 31 HOUR 4: Creating a Development Environment 33 Background of LAMP Stacks ................................................................ 33 Setting Up a Local Web Server .............................................................. 34 Securing Your Web Server .................................................................... 38 Development Tools.............................................................................. 41 Summary.......................................................................................... 45 Q&A ................................................................................................ 46 HOUR 5: Making Your First API Call 49 Making a Simple Twitter API Call.......................................................... 49 Making a Call in PHP.......................................................................... 53 v Contents Summary.......................................................................................... 57 Q&A ................................................................................................ 58 HOUR 6: Building a Simple Twitter Reader 59 Building Our First Twitter Client............................................................ 59 Twitter HTTP Response Codes................................................................ 65 Summary.......................................................................................... 69 Q&A ................................................................................................ 71 HOUR 7: Creating a Twitter API Framework 73 Twitter API Parameters........................................................................ 73 Creating an API Function for Twitter Function Calls ................................ 75 Summary.......................................................................................... 80 Q&A ................................................................................................ 80 HOUR 8: Twitter OAuth 81 What Is a Class and Why Do We Want to Use It? .................................... 81 What Is OAuth? ................................................................................ 82 How to Register Your Application.......................................................... 82 Creating the OAuth Twitter Class.......................................................... 83 PHP Library for Working with Twitter’s OAuth API .................................. 84 Setting Up the twitterOAuth Class ........................................................ 85 How to Add New Functions to Your Twitter Class Object............................ 90 How Our Class Deals with Twitter Connection Errors................................ 92 Summary.......................................................................................... 93 Q&A ................................................................................................ 93 HOUR 9: Building a Simple Twitter Client,Part I 95 Expanding the Index File to Support Tabs .............................................. 95 Adding Support for Home Timeline ...................................................... 97 Adding Support for Mentions................................................................ 99 Adding Support for Direct Messages .................................................... 101 Summary ........................................................................................ 102 Q&A .............................................................................................. 102 vi Teach Yourself the Twitter API in 24 Hours HOUR 10: Building a Simple Twitter Client,Part II 105 Updating and Adding New Files to Support Input Text Field .................... 105 Sending a Message to Twitter.............................................................. 108 API Call for Direct Messages .............................................................. 109 Sanitizing Messages .......................................................................... 110 Summary ........................................................................................ 110 Q&A .............................................................................................. 111 HOUR 11: Expanding Our Client for More API Calls 113 Types of API Method Calls.................................................................. 113 Adding Tabs to Our UI ...................................................................... 114 New Timeline API Calls: Retweeted...................................................... 117 New Status API Calls: Retweeted.......................................................... 119 Summary ........................................................................................ 123 Q&A .............................................................................................. 123 HOUR 12: Direct Messages 125 Sending a Direct Message .................................................................. 125 Adding Direct Message API Support .................................................... 127 Adding More Direct Message API Support ............................................ 131 The Destroy API Method .................................................................... 132 Summary ........................................................................................ 133 Q&A .............................................................................................. 133 HOUR 13: Lists 135 What Is a List?.................................................................................. 135 Implementing the List API into Our Application.................................... 137 Three Types of List Methods................................................................ 142 Summary ........................................................................................ 144 Q&A .............................................................................................. 144 HOUR 14: Favorites and User Methods 147 Favorites API Methods ...................................................................... 147 User API Methods.............................................................................. 153 Summary ........................................................................................ 158 Q&A .............................................................................................. 159 vii Contents HOUR 15: Search 161 History of Twitter Search API .............................................................. 161 Twitter’s Stance on Search .................................................................. 161 The Lone Search API.......................................................................... 162 A Quick Guide to More Information on Search from the Twitter Docs........ 170 Summary ........................................................................................ 173 Q&A .............................................................................................. 174 HOUR 16: Trends and GEO 177 What Is a Trending Topic?.................................................................. 177 Supporting Trends in Our Application.................................................. 177 Understanding the GEO Tag................................................................ 187 Summary ........................................................................................ 190 Q&A .............................................................................................. 190 HOUR 17: Friendships,Notification,Block,and Account Methods 193 Friendships Methods.......................................................................... 193 Notification Methods ........................................................................ 197 Block Methods.................................................................................. 198 Account Methods.............................................................................. 199 Summary ........................................................................................ 202 Q&A .............................................................................................. 202 HOUR 18: Twitter Documentation 205 The Twitter Dev Website .................................................................... 205 Dev.twitter.com/doc .......................................................................... 211 Twitter Resource Page Overview .......................................................... 212 Summary ........................................................................................ 216 Q&A .............................................................................................. 216 HOUR 19: Streaming API 219 The Three Types of Streaming APIs...................................................... 219 Streaming Methods .......................................................................... 222 Summary ........................................................................................ 226 Q&A .............................................................................................. 226 viii Teach Yourself the Twitter API in 24 Hours HOUR 20: FailWhale and the Future of the API 229 . . . . . . . . . . . . . . . . . . What Is Spotting the FailWhale? . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Review of the Application We Just Built . . . . . . . . . . . . . . . . . . . . . 231 Where Is the Twitter API Going? . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 HOUR 21: Getting Started in Twitter Android Application 241 . . . . . . . . . . . Introducing Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Creating the Hello Android Project . . . . . . . . . . . . . . . . . . . . . . . . 243 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 HOUR 22: Building Android Applications with Twitter 255 . . . . . . . . . . . . . . Using Twitter OAuth in Android . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Importing Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 HOUR 23: Getting Started with Twitter Using iOS 279 . . . . . . . . . . . . . . . . . Introducing iOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Creating a Hello World Application . . . . . . . . . . . . . . . . . . . . . . . . 280 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 HOUR 24: Building an iPhone and iPod Touch Application with Twitter 293 . . Introducing Twitter xAuth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 Benefits of Using Twitter xAuth . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Selecting Twitter Objective-C Libraries . . . . . . . . . . . . . . . . . . . . . . 294 Loading xAuth Token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 Posting Tweet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 Adding MGTwitterEngine Delegate Methods . . . . . . . . . . . . . . . . . . 305 Creating Objects in Interface Builder . . . . . . . . . . . . . . . . . . . . . . . 308 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .316 INDEX 319 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Author Dr. Christopher Perireceived his Doctorate from the University of California, Berkeley, in Architecture. His focus was on Collaboration in Virtual Environments delving into methods that facilitate designers and engineers to improve communication over remote networks. He started playing with the Twitter API very early in the API release, creating his own Twitter client called TwittFilter, which is geared more to the occasional user then some- one who uses Twitter all the time. As time went on, he added more and more features and functions for his own personal use, until one day he realized he had a fairly sophisticated application and opened it up to the general public to use. He learned quite a bit about the Twitter API the hard way—by simply coding things up and seeing what happens. Although TwittFilter is still a personalproject, he has already created a number of private Twitter applications, robots, and smaller projects like NewsSnacker.com, which is open to the public.

Description:
In just 24 sessions of one hour or less, you’ll learn how to build great new social applications with the latest versions of the Twitter API. Using this book’s straightforward, step-by-step approach, you’ll discover all you can do with the Twitter API, and master everything from the absolute b
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.