SlideShare una empresa de Scribd logo
1 de 21
iPhone Developer Advance Program




                              by Eakapong Kattiya
Wednesday, October 27, 2010
ความรู้พื้นฐานที่จําเป็น

                 - Objective-C for iPhone Programming

                 - Basic UI iPhone Programming

                 - Model View Controller

                 - XML / JSON

                 - OAuth




Wednesday, October 27, 2010
What is twitter

                    ทวิตเตอร์ (Twitter) คือเว็บไซต์ที่ให้บริการ blog สั้นๆ หรือที่
            ภาษาอังกฤษเรียกกันว่า Micro-Blog ซึ่งสามารถให้ผู้ใช้ส่งข้อความ
            ของตนเอง ให้เพื่อน ๆ ที่ติดตาม twitter ของเราอยู่อ่านได้ และเรา
            เองก็สามารถอ่านข้อความของเพื่อน หรือคนที่เราติดตามเขาอยู่ได้
            ซึ่ง twitter ก็ถือได้ว่าเป็นเว็บไซต์ประเภท social media ด้วยเช่นกัน


                 ใน รูปแบบของ twitter นี้ ที่เรียกว่าเป็น blog สั้นก็เพราะว่า
            twitter ให้เขียนข้อความได้ครั้งละไม่เกิน 140 ตัวอักษร ซึ่งข้อความ
            นี้เมื่อเขียนแล้วจะไปแสดงอยู่ในหน้า profile ของผู้เขียนนั่นเอง และ
            จะทําการส่งข้อความนี้ไปยังสมาชิกที่ติดตามผู้เขียนคนนั้นอยู่
            (follower) โดยอัตโนมัติ
                  




                                                          ที่มา http://beta.i3.in.th/content/view/2094


Wednesday, October 27, 2010
What is twitter

                    แต่สิ่งหนึ่งที่มาช่วยให้ Twitter มีประโยชน์ และสนุกมากขึ้น ก็
            คือ คุณสามารถติดตาม (Follow) คนอื่นๆ ที่เขาเขียนข้อความลงไป
            ใน Twitter ของเขาได้ ว่าเขาคนนั้นกําลังทําอะไรอยู่ โดยเมื่อคุณ
            ติดตาม (Follow) เขาแล้ว เมื่อคนนั้นเขาทําอะไรและพิมพ์อะไรลงไป
            ใน Twitter คุณก็ได้รับข้อความเหล่านั้นด้วยไปพร้อมๆ กัน และก็
            สามารถติดตามได้ทีละหลายๆ คน ซึ่งก็จะทําให้คุณทราบว่าเขาเหล่า
            นั้นกําลังทําอะไรอยู่ในขณะนั้นทันที




                                                        ที่มา http://beta.i3.in.th/content/view/2094


Wednesday, October 27, 2010
ประโยชน์ของ twitter ที่มีต่อการตลาด


                 เป็นเครื่องมือทางการตลาด
                        สามารถ ใช้เป็นเครื่องทางการตลาดในการสื่อสาร กับกลุ่มเป้าหมายของสินค้าหรือ
                 บริการได้ดี เพราะสามารถสื่อสารได้แบบทันที (Real time) และยังสามารถใช้เป็นเครื่องมือใน
                 การสร้างความสัมพันธ์ (Relation) กับกลุ่มเป้าหมายได้ดีอีกด้วย


                  สร้างการรับรู้ของ Brand 
                        การสื่อสารผ่าน Twitter ไปยังกลุ่มเป้าหมายบ่อยๆ จะทําให้การรับรู้ของ Brand ดีขึ้น
                 และจะรู้สึกคุ้นเคยกับ Brand ดีขึ้นเช่นกัน ทําให้สามารถสร้างความต่อเนื่องของ Brand ได้


                  ช่องทางกระจายข้อมูลข่าวสารช่องทางใหม่
                       ตอนนี้มีหลายๆ เว็บไซต์ เริ่มมีการนํา Twitter มาเป็นช่องทางหนึ่งในการ ส่งข้อมูลล่าสุด
                 ที่ทางเว็บไซต์มี เช่น สํานักข่าวต่างประเทศหลายๆ แห่งเช่น BBC (http://twitter.com/
                 bbctech), CNN, BusinessWeek, ESPN, CNET (http://twitter.com/cnetnews) ก็เริ่มนํา
                 Twitter มาใช้ในการส่งข่าว ให้กับผู้ที่สนใจ สามารถติดตามผ่าน Twitter ได้ทันที  


                                                         ที่มา http://beta.i3.in.th/content/view/2094


Wednesday, October 27, 2010
ประโยชน์ของ twitter ที่มีต่อการตลาด


                 แจ้งข้อมูลสินค้าหรือบริการใหม่ๆ 
                        มีหลายๆ เว็บไซต์เริ่มนํา Twitter มาใช้ในการ แจ้งข้อมูลสินค้าใหม่ๆ ให้กับผู้ที่สนใจ
                 สามารถติดตาม จากเว็บไซต์ได้ทันทีผ่าน Twitter เช่น เว็บไซต์ Amazon.com ใช้ Twitter ส่ง
                 โปรโมชั่นสินค้าใหม่ๆ ผ่าน Twitter http://twitter.com/amazondeals หรือเว็บไซต์
                 www.woot.com เว็บไซต์ขายสินค้า ก็มี Twitter ให้บริการ  ติดตามได้ที่ http://twitter.com/
                 woot


                 เครื่องมือในการศึกษาข้อมูล
                           เราสามารถใช้ Twitter เป็นเครื่องมือในการศึกษา และวิเคราะห์ว่า ตอนนี้ Brand หรือ
                 สินค้า-บริการของเรา มีใครพูดถึงบ้างใน Twitter และเขาพูดถึงในมุมไหน? และยังสามารถใช้
                 ศึกษาพฤติกรรมของลุกค้า หรือกลุ่มเป้าหมายของเราได้ดีอีกด้วย โดยมีเครื่องมือหลายอย่าง
                 ที่สามารถจะนํามาใช้ Monitor และติดตามความเคลื่อนไหวหรือพฤติกรรมของกลุ่มเป้าหมาย
                 ได้


                                                      ที่มา http://beta.i3.in.th/content/view/2094




Wednesday, October 27, 2010
What is OAuth

           รู้จักกับ OAuth

           OAuth ก็คือ Protocol ในการแลกเปลี่ยน User Identity แบบหนึ่ง ซึ่งใช้ระบบ Token
           กล่าวคือ ถ้าเราหรือตัว Application ที่เป็นคนกลางต้องการจะทําอะไร ในฐานะ User
           ได้ เราก็ต้องมี Token ที่ยืนยันว่าเราได้รับสิทธิ์จากผู้ใช้เสียก่อน ซึ่งระบบ Token นี้
           ทําให้เกิดความปลอดภัยมากกว่า Protocol แบบดั้งเดิมคือ User ไม่ต้องบอก
           username และ password แก่ คนกลางหรือ Application โดยตรง

               แต่จะทําการ Login ผ่าน Twitter แล้ว Server Twitter จะส่ง Token มาให้ iphone
           เพื่อทํางานเสมือนว่าเป็นผู้ใช้เอง

                                                 รายละเอียดเพิ่มเติม http://oauth.net/




Wednesday, October 27, 2010
Wednesday, October 27, 2010
How to start ?
           เราจะสร้าง iphone application เพื่อทําการ Tweet ข้อความของเรา
           ด้วย iPhone SDK โดยเริ่มจากการ

             1. สมัคร Twitter Account
                www.twitter.com

             2. สร้าง Twitter Application
                http://twitter.com/apps/new

             3. Download Twitter-OAuth-iphone source
                http://github.com/bengottlieb/Twitter-OAuth-iPhone




Wednesday, October 27, 2010
Step1. Import Twitter-OAuth-iphone to project
           เริ่มจากการ download at  http://github.com/bengottlieb/Twitter-
           OAuth-iPhone และเปิดProject TwitterRush-Complete ให้เสร็จ
           เรียบร้อย จากนั้นให้ link เข้ามาใช้ใน project ของเราดังนี้

             1. ในขณะที่เราเปิดโปรเจ็คของเราอยู่ ให้เปิดไฟล์
                ชื่อ TwitterRush.xcodeproj ซึ่งอยู่ในโฟลเดอร์ชื่อ src ของไฟล์ที่
                เรา download มา
             2. ลาก group ที่ชื่อ Twitter+OAuth ที่อยู่ใน project ที่เรา
                download มาลงไปใส่ในโปรเจ็คของเรา (เลือก Copy items
                into destination group’s folder (if needed)
             3. click ขวาที่โปรเจ็คของเราแล้วเลือก Get Info, ใน tab Build ให้
                ไปกําหนดค่าของ User Header Search Paths เป็น path
                ตําแหน่ง directory ของไฟล์ FBConnect.xcodeproj ที่เราเปิด
                ในข้อ 1 เท่านี้ก็เรียบร้อย




Wednesday, October 27, 2010
Step 2: Add the libxml2 Library

             1. Add Framework libxml2.dylib

             2. click ขวาที่โปรเจ็คของเราแล้วเลือก Get Info, ใน tab Build ให้
                ไปกําหนดค่าของ Header Search Paths เป็น path
                  $(SDKROOT)/usr/include/libxml2

                 โดยเลือกแบบ Recursive คือเอา sub folder ทุกตัวมาด้วย




Wednesday, October 27, 2010
Step 3: Declare the NSXMLParserDelegate
             ทําการขจัด warning ที่มีด้วยการประกาศ NSXMLParserDelegate
             ให้กับ Class MGTwitterXMLParser และ MGTwitterXMLParser

             เนื่องจากมีการเรียกใช้ NSXMLParser ใน Class ทั้งสองนี้


 @interface MGTwitterStatusesParser : MGTwitterXMLParser <NSXMLParserDelegate> {



 @interface MGTwitterXMLParser : NSObject <NSXMLParserDelegate> {




Wednesday, October 27, 2010
Step 4: Import SA_OAuthTwitterController.h & Declare
                   SA_OAuthTwitterEngine
                                    TwitterRushViewController.h
      #import <UIKit/UIKit.h>
      #import "SA_OAuthTwitterController.h"

      @class SA_OAuthTwitterEngine;

      @interface TwitterRushViewController : UIViewController <UITextFieldDelegate,
      SA_OAuthTwitterControllerDelegate>
      {
      ! IBOutlet UITextField      *tweetTextField;

      !     SA_OAuthTwitterEngine   *_engine;
      }

      @property(nonatomic, retain) IBOutlet UITextField *tweetTextField;

      -(IBAction)updateTwitter:(id)sender;

      @end




Wednesday, October 27, 2010
Step 5: Import SA_OAuthTwitterEngine สําหรับสร้าง Token ในการติดต่อกับ
           Twitter API

                                  TwitterRushViewController.m

      #import "SA_OAuthTwitterEngine.h" //we need SA_OAuthTwitterControllerDelegate

      #define kOAuthConsumerKey         @"Your consumer key here"
      #define kOAuthConsumerSecret      @"Your consumer secret here"

      - (void)viewDidAppear: (BOOL)animated {

      !     if(!_engine){
      !     ! _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
      !     ! _engine.consumerKey    = kOAuthConsumerKey;
      !     ! _engine.consumerSecret = kOAuthConsumerSecret;
      !     }

      }




Wednesday, October 27, 2010
Step 6: สร้าง Login Screen
                                     TwitterRushViewController.m

      - (void)viewDidAppear: (BOOL)animated {

      !     if(!_engine){
      !     ! _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
      !     ! _engine.consumerKey    = kOAuthConsumerKey;
      !     ! _engine.consumerSecret = kOAuthConsumerSecret;
      !     }

             //Create Login Screen if user never login before
      !     if(![_engine isAuthorized]){

            !    UIViewController *vcController = [SA_OAuthTwitterController
                           controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
            !    if (controller){
            !    ! [self presentModalViewController: vcController animated: YES];
            !    }
            }
      }




Wednesday, October 27, 2010
Step 7: สร้าง Delegate สําหรับ Login Screen


                                  TwitterRushViewController.m
      #pragma mark SA_OAuthTwitterEngineDelegate

      - (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *)
      username {
      ! NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

      !     [defaults setObject: data forKey: @"authData"];
      !     [defaults synchronize];
      }

      - (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
      ! return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
      }




Wednesday, October 27, 2010
Step 8: Post ข้อความบน Tweeter

          โดยเรียกผ่าน Method sendUpdate ของ SA_OAuthTwitterEngine
          โดยประกาศ Delegate requestSucceeded และ requestFailed
          สําหรับตรวจสอบสถานะการ Tweet ว่าสําเร็จหรือไม่

                                   TwitterRushViewController.m
      [_engine sendUpdate:tweetTextField.text];


      #pragma mark TwitterEngineDelegate
      - (void) requestSucceeded: (NSString *) requestIdentifier {
      ! NSLog(@"Request %@ succeeded", requestIdentifier);
      }

      - (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *)
      error {
      ! NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
      }




Wednesday, October 27, 2010
Appendix : Search ข้อความบน Tweeter



                                TwitterRushViewController.m
      -(IBAction)searchTweet:(id)sender{
      ! // Add the view controller's view to the window and display.
      ! responseData = [[NSMutableData data] retain];
      !
      ! NSURLRequest *request = [NSURLRequest requestWithURL:
      ! [NSURL URLWithString:@"http://search.twitter.com/search.json?q=netdesign&rpp=10"]];
      ! [[NSURLConnection alloc] initWithRequest:request delegate:self];
      !
      !
      }




Wednesday, October 27, 2010
Appendix : การดึงข้อมูล User Timeline

                               TwitterRushViewController.m

  #pragma mark UserTimeLine
  -(IBAction)showUserTimeline:(id)sender{
  !
  ! [_engine getUserTimelineFor:_engine.username sinceID:0 startingAtPage:0 count:10];


  }

  //Delegate when API return value
  - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier {



  }
  !
                                              }




Wednesday, October 27, 2010
Appendix : การดึงข้อมูลจาก API ผ่าน MGTwitterEngine


                                   รายละเอียดของค่าที่ส่งมาจาก API แบบต่าง ๆ

                                  http://dev.twitter.com/doc
                                                 MGTwitterEngine.h
      - (NSString *)getPublicTimeline; // statuses/public_timeline

      - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; //
      statuses/friends_timeline
      - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)
      pageNum count:(int)count; // statuses/friends_timeline

      - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:
      (int)count; // statuses/user_timeline & statuses/user_timeline/user
      - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID
      startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user

      - (NSString *)getUpdate:(unsigned long)updateID; // statuses/show
      - (NSString *)sendUpdate:(NSString *)status; // statuses/update
      - (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID; // statuses/update

      - (NSString *)getRepliesStartingAtPage:(int)pageNum; // statuses/mentions
      - (NSString *)getRepliesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/
      mentions
      - (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum
      count:(int)count; // statuses/mentions

      - (NSString *)deleteUpdate:(unsigned long)updateID; // statuses/destroy

      - (NSString *)getFeaturedUsers; // statuses/features (undocumented, returns invalid JSON data)




Wednesday, October 27, 2010
Demo




Wednesday, October 27, 2010

Más contenido relacionado

Destacado

Pristine sun teaser 1Q 2015
Pristine sun teaser 1Q 2015Pristine sun teaser 1Q 2015
Pristine sun teaser 1Q 2015Troy Helming
 
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
(1 July 2013) iOS Basic Development Day 5 - Submit to App StoreEakapong Kattiya
 
Android basic 4 Navigation Drawer
Android basic 4 Navigation DrawerAndroid basic 4 Navigation Drawer
Android basic 4 Navigation DrawerEakapong Kattiya
 
Evrdi : Social Diary ( iOS and Android )
Evrdi : Social Diary ( iOS and Android )Evrdi : Social Diary ( iOS and Android )
Evrdi : Social Diary ( iOS and Android )Eakapong Kattiya
 
Android Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADTAndroid Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADTEakapong Kattiya
 
(31 July 2013) iOS Basic Development Day 2 Human interface design
(31 July 2013) iOS Basic Development Day 2 Human interface design (31 July 2013) iOS Basic Development Day 2 Human interface design
(31 July 2013) iOS Basic Development Day 2 Human interface design Eakapong Kattiya
 

Destacado (8)

Pristine sun teaser 1Q 2015
Pristine sun teaser 1Q 2015Pristine sun teaser 1Q 2015
Pristine sun teaser 1Q 2015
 
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
(1 July 2013) iOS Basic Development Day 5 - Submit to App Store
 
Android basic 4 Navigation Drawer
Android basic 4 Navigation DrawerAndroid basic 4 Navigation Drawer
Android basic 4 Navigation Drawer
 
Android basic 2 UI Design
Android basic 2 UI DesignAndroid basic 2 UI Design
Android basic 2 UI Design
 
Evrdi : Social Diary ( iOS and Android )
Evrdi : Social Diary ( iOS and Android )Evrdi : Social Diary ( iOS and Android )
Evrdi : Social Diary ( iOS and Android )
 
Android basic 3 Dialogs
Android basic 3 DialogsAndroid basic 3 Dialogs
Android basic 3 Dialogs
 
Android Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADTAndroid Basic Development Day 1 Introduction & ADT
Android Basic Development Day 1 Introduction & ADT
 
(31 July 2013) iOS Basic Development Day 2 Human interface design
(31 July 2013) iOS Basic Development Day 2 Human interface design (31 July 2013) iOS Basic Development Day 2 Human interface design
(31 July 2013) iOS Basic Development Day 2 Human interface design
 

Similar a Iphone developer advance twitter

บทที่2
บทที่2บทที่2
บทที่2dargonbail
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2teeraratWI
 
คู่มือ Twitter V2
คู่มือ Twitter V2คู่มือ Twitter V2
คู่มือ Twitter V2Pakornkrits
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2teerarat55
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2teerarat55
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2teeraratWI
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้องKot สุรศักดิ์
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้องKot สุรศักดิ์
 
บทที่2
บทที่2บทที่2
บทที่2Tangkwa Tom
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้องChi Cha Pui Fai
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้องChi Cha Pui Fai
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้องChi Cha Pui Fai
 
Onettemplate
OnettemplateOnettemplate
Onettemplatechycindy
 

Similar a Iphone developer advance twitter (20)

บทที่ 2 ทวีชัย
บทที่ 2 ทวีชัยบทที่ 2 ทวีชัย
บทที่ 2 ทวีชัย
 
บทที่2
บทที่2บทที่2
บทที่2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
คู่มือ Twitter V2
คู่มือ Twitter V2คู่มือ Twitter V2
คู่มือ Twitter V2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
บทที่222222+++
บทที่222222+++บทที่222222+++
บทที่222222+++
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
3 3
3 33 3
3 3
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
 
บทที่2
บทที่2บทที่2
บทที่2
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
 
บทที่2
บทที่2 บทที่2
บทที่2
 
Wordpress
WordpressWordpress
Wordpress
 
Internet-Social Media
Internet-Social MediaInternet-Social Media
Internet-Social Media
 
Onettemplate
OnettemplateOnettemplate
Onettemplate
 

Iphone developer advance twitter

  • 1. iPhone Developer Advance Program by Eakapong Kattiya Wednesday, October 27, 2010
  • 2. ความรู้พื้นฐานที่จําเป็น - Objective-C for iPhone Programming - Basic UI iPhone Programming - Model View Controller - XML / JSON - OAuth Wednesday, October 27, 2010
  • 3. What is twitter         ทวิตเตอร์ (Twitter) คือเว็บไซต์ที่ให้บริการ blog สั้นๆ หรือที่ ภาษาอังกฤษเรียกกันว่า Micro-Blog ซึ่งสามารถให้ผู้ใช้ส่งข้อความ ของตนเอง ให้เพื่อน ๆ ที่ติดตาม twitter ของเราอยู่อ่านได้ และเรา เองก็สามารถอ่านข้อความของเพื่อน หรือคนที่เราติดตามเขาอยู่ได้ ซึ่ง twitter ก็ถือได้ว่าเป็นเว็บไซต์ประเภท social media ด้วยเช่นกัน      ใน รูปแบบของ twitter นี้ ที่เรียกว่าเป็น blog สั้นก็เพราะว่า twitter ให้เขียนข้อความได้ครั้งละไม่เกิน 140 ตัวอักษร ซึ่งข้อความ นี้เมื่อเขียนแล้วจะไปแสดงอยู่ในหน้า profile ของผู้เขียนนั่นเอง และ จะทําการส่งข้อความนี้ไปยังสมาชิกที่ติดตามผู้เขียนคนนั้นอยู่ (follower) โดยอัตโนมัติ        ที่มา http://beta.i3.in.th/content/view/2094 Wednesday, October 27, 2010
  • 4. What is twitter         แต่สิ่งหนึ่งที่มาช่วยให้ Twitter มีประโยชน์ และสนุกมากขึ้น ก็ คือ คุณสามารถติดตาม (Follow) คนอื่นๆ ที่เขาเขียนข้อความลงไป ใน Twitter ของเขาได้ ว่าเขาคนนั้นกําลังทําอะไรอยู่ โดยเมื่อคุณ ติดตาม (Follow) เขาแล้ว เมื่อคนนั้นเขาทําอะไรและพิมพ์อะไรลงไป ใน Twitter คุณก็ได้รับข้อความเหล่านั้นด้วยไปพร้อมๆ กัน และก็ สามารถติดตามได้ทีละหลายๆ คน ซึ่งก็จะทําให้คุณทราบว่าเขาเหล่า นั้นกําลังทําอะไรอยู่ในขณะนั้นทันที ที่มา http://beta.i3.in.th/content/view/2094 Wednesday, October 27, 2010
  • 5. ประโยชน์ของ twitter ที่มีต่อการตลาด เป็นเครื่องมือทางการตลาด        สามารถ ใช้เป็นเครื่องทางการตลาดในการสื่อสาร กับกลุ่มเป้าหมายของสินค้าหรือ บริการได้ดี เพราะสามารถสื่อสารได้แบบทันที (Real time) และยังสามารถใช้เป็นเครื่องมือใน การสร้างความสัมพันธ์ (Relation) กับกลุ่มเป้าหมายได้ดีอีกด้วย  สร้างการรับรู้ของ Brand         การสื่อสารผ่าน Twitter ไปยังกลุ่มเป้าหมายบ่อยๆ จะทําให้การรับรู้ของ Brand ดีขึ้น และจะรู้สึกคุ้นเคยกับ Brand ดีขึ้นเช่นกัน ทําให้สามารถสร้างความต่อเนื่องของ Brand ได้  ช่องทางกระจายข้อมูลข่าวสารช่องทางใหม่       ตอนนี้มีหลายๆ เว็บไซต์ เริ่มมีการนํา Twitter มาเป็นช่องทางหนึ่งในการ ส่งข้อมูลล่าสุด ที่ทางเว็บไซต์มี เช่น สํานักข่าวต่างประเทศหลายๆ แห่งเช่น BBC (http://twitter.com/ bbctech), CNN, BusinessWeek, ESPN, CNET (http://twitter.com/cnetnews) ก็เริ่มนํา Twitter มาใช้ในการส่งข่าว ให้กับผู้ที่สนใจ สามารถติดตามผ่าน Twitter ได้ทันที   ที่มา http://beta.i3.in.th/content/view/2094 Wednesday, October 27, 2010
  • 6. ประโยชน์ของ twitter ที่มีต่อการตลาด แจ้งข้อมูลสินค้าหรือบริการใหม่ๆ         มีหลายๆ เว็บไซต์เริ่มนํา Twitter มาใช้ในการ แจ้งข้อมูลสินค้าใหม่ๆ ให้กับผู้ที่สนใจ สามารถติดตาม จากเว็บไซต์ได้ทันทีผ่าน Twitter เช่น เว็บไซต์ Amazon.com ใช้ Twitter ส่ง โปรโมชั่นสินค้าใหม่ๆ ผ่าน Twitter http://twitter.com/amazondeals หรือเว็บไซต์ www.woot.com เว็บไซต์ขายสินค้า ก็มี Twitter ให้บริการ  ติดตามได้ที่ http://twitter.com/ woot เครื่องมือในการศึกษาข้อมูล           เราสามารถใช้ Twitter เป็นเครื่องมือในการศึกษา และวิเคราะห์ว่า ตอนนี้ Brand หรือ สินค้า-บริการของเรา มีใครพูดถึงบ้างใน Twitter และเขาพูดถึงในมุมไหน? และยังสามารถใช้ ศึกษาพฤติกรรมของลุกค้า หรือกลุ่มเป้าหมายของเราได้ดีอีกด้วย โดยมีเครื่องมือหลายอย่าง ที่สามารถจะนํามาใช้ Monitor และติดตามความเคลื่อนไหวหรือพฤติกรรมของกลุ่มเป้าหมาย ได้ ที่มา http://beta.i3.in.th/content/view/2094 Wednesday, October 27, 2010
  • 7. What is OAuth รู้จักกับ OAuth OAuth ก็คือ Protocol ในการแลกเปลี่ยน User Identity แบบหนึ่ง ซึ่งใช้ระบบ Token กล่าวคือ ถ้าเราหรือตัว Application ที่เป็นคนกลางต้องการจะทําอะไร ในฐานะ User ได้ เราก็ต้องมี Token ที่ยืนยันว่าเราได้รับสิทธิ์จากผู้ใช้เสียก่อน ซึ่งระบบ Token นี้ ทําให้เกิดความปลอดภัยมากกว่า Protocol แบบดั้งเดิมคือ User ไม่ต้องบอก username และ password แก่ คนกลางหรือ Application โดยตรง แต่จะทําการ Login ผ่าน Twitter แล้ว Server Twitter จะส่ง Token มาให้ iphone เพื่อทํางานเสมือนว่าเป็นผู้ใช้เอง รายละเอียดเพิ่มเติม http://oauth.net/ Wednesday, October 27, 2010
  • 9. How to start ? เราจะสร้าง iphone application เพื่อทําการ Tweet ข้อความของเรา ด้วย iPhone SDK โดยเริ่มจากการ 1. สมัคร Twitter Account www.twitter.com 2. สร้าง Twitter Application http://twitter.com/apps/new 3. Download Twitter-OAuth-iphone source http://github.com/bengottlieb/Twitter-OAuth-iPhone Wednesday, October 27, 2010
  • 10. Step1. Import Twitter-OAuth-iphone to project เริ่มจากการ download at  http://github.com/bengottlieb/Twitter- OAuth-iPhone และเปิดProject TwitterRush-Complete ให้เสร็จ เรียบร้อย จากนั้นให้ link เข้ามาใช้ใน project ของเราดังนี้ 1. ในขณะที่เราเปิดโปรเจ็คของเราอยู่ ให้เปิดไฟล์ ชื่อ TwitterRush.xcodeproj ซึ่งอยู่ในโฟลเดอร์ชื่อ src ของไฟล์ที่ เรา download มา 2. ลาก group ที่ชื่อ Twitter+OAuth ที่อยู่ใน project ที่เรา download มาลงไปใส่ในโปรเจ็คของเรา (เลือก Copy items into destination group’s folder (if needed) 3. click ขวาที่โปรเจ็คของเราแล้วเลือก Get Info, ใน tab Build ให้ ไปกําหนดค่าของ User Header Search Paths เป็น path ตําแหน่ง directory ของไฟล์ FBConnect.xcodeproj ที่เราเปิด ในข้อ 1 เท่านี้ก็เรียบร้อย Wednesday, October 27, 2010
  • 11. Step 2: Add the libxml2 Library 1. Add Framework libxml2.dylib 2. click ขวาที่โปรเจ็คของเราแล้วเลือก Get Info, ใน tab Build ให้ ไปกําหนดค่าของ Header Search Paths เป็น path $(SDKROOT)/usr/include/libxml2 โดยเลือกแบบ Recursive คือเอา sub folder ทุกตัวมาด้วย Wednesday, October 27, 2010
  • 12. Step 3: Declare the NSXMLParserDelegate ทําการขจัด warning ที่มีด้วยการประกาศ NSXMLParserDelegate ให้กับ Class MGTwitterXMLParser และ MGTwitterXMLParser เนื่องจากมีการเรียกใช้ NSXMLParser ใน Class ทั้งสองนี้ @interface MGTwitterStatusesParser : MGTwitterXMLParser <NSXMLParserDelegate> { @interface MGTwitterXMLParser : NSObject <NSXMLParserDelegate> { Wednesday, October 27, 2010
  • 13. Step 4: Import SA_OAuthTwitterController.h & Declare SA_OAuthTwitterEngine TwitterRushViewController.h #import <UIKit/UIKit.h> #import "SA_OAuthTwitterController.h" @class SA_OAuthTwitterEngine; @interface TwitterRushViewController : UIViewController <UITextFieldDelegate, SA_OAuthTwitterControllerDelegate> { ! IBOutlet UITextField *tweetTextField; ! SA_OAuthTwitterEngine *_engine; } @property(nonatomic, retain) IBOutlet UITextField *tweetTextField; -(IBAction)updateTwitter:(id)sender; @end Wednesday, October 27, 2010
  • 14. Step 5: Import SA_OAuthTwitterEngine สําหรับสร้าง Token ในการติดต่อกับ Twitter API TwitterRushViewController.m #import "SA_OAuthTwitterEngine.h" //we need SA_OAuthTwitterControllerDelegate #define kOAuthConsumerKey @"Your consumer key here" #define kOAuthConsumerSecret @"Your consumer secret here" - (void)viewDidAppear: (BOOL)animated { ! if(!_engine){ ! ! _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; ! ! _engine.consumerKey = kOAuthConsumerKey; ! ! _engine.consumerSecret = kOAuthConsumerSecret; ! } } Wednesday, October 27, 2010
  • 15. Step 6: สร้าง Login Screen TwitterRushViewController.m - (void)viewDidAppear: (BOOL)animated { ! if(!_engine){ ! ! _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; ! ! _engine.consumerKey = kOAuthConsumerKey; ! ! _engine.consumerSecret = kOAuthConsumerSecret; ! } //Create Login Screen if user never login before ! if(![_engine isAuthorized]){ ! UIViewController *vcController = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self]; ! if (controller){ ! ! [self presentModalViewController: vcController animated: YES]; ! } } } Wednesday, October 27, 2010
  • 16. Step 7: สร้าง Delegate สําหรับ Login Screen TwitterRushViewController.m #pragma mark SA_OAuthTwitterEngineDelegate - (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username { ! NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; ! [defaults setObject: data forKey: @"authData"]; ! [defaults synchronize]; } - (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username { ! return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"]; } Wednesday, October 27, 2010
  • 17. Step 8: Post ข้อความบน Tweeter โดยเรียกผ่าน Method sendUpdate ของ SA_OAuthTwitterEngine โดยประกาศ Delegate requestSucceeded และ requestFailed สําหรับตรวจสอบสถานะการ Tweet ว่าสําเร็จหรือไม่ TwitterRushViewController.m [_engine sendUpdate:tweetTextField.text]; #pragma mark TwitterEngineDelegate - (void) requestSucceeded: (NSString *) requestIdentifier { ! NSLog(@"Request %@ succeeded", requestIdentifier); } - (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error { ! NSLog(@"Request %@ failed with error: %@", requestIdentifier, error); } Wednesday, October 27, 2010
  • 18. Appendix : Search ข้อความบน Tweeter TwitterRushViewController.m -(IBAction)searchTweet:(id)sender{ ! // Add the view controller's view to the window and display. ! responseData = [[NSMutableData data] retain]; ! ! NSURLRequest *request = [NSURLRequest requestWithURL: ! [NSURL URLWithString:@"http://search.twitter.com/search.json?q=netdesign&rpp=10"]]; ! [[NSURLConnection alloc] initWithRequest:request delegate:self]; ! ! } Wednesday, October 27, 2010
  • 19. Appendix : การดึงข้อมูล User Timeline TwitterRushViewController.m #pragma mark UserTimeLine -(IBAction)showUserTimeline:(id)sender{ ! ! [_engine getUserTimelineFor:_engine.username sinceID:0 startingAtPage:0 count:10]; } //Delegate when API return value - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier { } ! } Wednesday, October 27, 2010
  • 20. Appendix : การดึงข้อมูลจาก API ผ่าน MGTwitterEngine รายละเอียดของค่าที่ส่งมาจาก API แบบต่าง ๆ http://dev.twitter.com/doc MGTwitterEngine.h - (NSString *)getPublicTimeline; // statuses/public_timeline - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int) pageNum count:(int)count; // statuses/friends_timeline - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count: (int)count; // statuses/user_timeline & statuses/user_timeline/user - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user - (NSString *)getUpdate:(unsigned long)updateID; // statuses/show - (NSString *)sendUpdate:(NSString *)status; // statuses/update - (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID; // statuses/update - (NSString *)getRepliesStartingAtPage:(int)pageNum; // statuses/mentions - (NSString *)getRepliesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/ mentions - (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions - (NSString *)deleteUpdate:(unsigned long)updateID; // statuses/destroy - (NSString *)getFeaturedUsers; // statuses/features (undocumented, returns invalid JSON data) Wednesday, October 27, 2010