Skip to content

Instantly share code, notes, and snippets.

@shoya140
Last active August 29, 2015 14:09
Show Gist options
  • Save shoya140/4be05625360823f87162 to your computer and use it in GitHub Desktop.
Save shoya140/4be05625360823f87162 to your computer and use it in GitHub Desktop.
login on twitter
//
// 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