Last active
August 29, 2015 14:09
-
-
Save shoya140/4be05625360823f87162 to your computer and use it in GitHub Desktop.
login on twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// Twitter-Practice | |
// | |
// Created by ishimaru on 2014/11/09. | |
// Copyright (c) 2014 shoya140. All rights reserved. | |
// | |
#import "ViewController.h" | |
#import "STTwitter.h" | |
#define TIMEOUT_LIMIT 10 | |
@interface ViewController (){ | |
STTwitterAPI *twitter; | |
BOOL userLogined; | |
int timeOutCount; | |
} | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
twitter = [STTwitterAPI twitterAPIOSWithFirstAccount]; | |
userLogined = NO; | |
timeOutCount = 0; | |
[self getTimeLine]; | |
} | |
- (void)getTimeLine | |
{ | |
if (!userLogined) { | |
if (timeOutCount < TIMEOUT_LIMIT) { | |
// ログインしてからもう一度取得 | |
[self login]; | |
[self performSelector:@selector(getTimeLine) withObject:nil afterDelay:1.0]; | |
}else{ | |
// 何度も失敗するのでオフラインかTwitterアカウントを登録していない可能性あり | |
} | |
} | |
[twitter getHomeTimelineSinceID:nil count:100 successBlock:^(NSArray *statuses) { | |
NSLog(@"data:%@", statuses); | |
} errorBlock:^(NSError *error) { | |
NSLog(@"Error:%@", error); | |
}]; | |
} | |
- (void)login | |
{ | |
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) { | |
NSLog(@"Verify success:%@", username); | |
userLogined = YES; | |
timeOutCount = 0; | |
} errorBlock:^(NSError *error) { | |
NSLog(@"Error:%@", error); | |
}]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment