added logo
This commit is contained in:
parent
1f15ec227c
commit
e58d1ef140
9 changed files with 198 additions and 40 deletions
75
OAuth.m
75
OAuth.m
|
@ -30,6 +30,7 @@
|
|||
if (self = [super init]) {
|
||||
self.consumerToken = [[OAToken alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
||||
self.accessToken = [[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:OAUTH_SERVICE_NAME prefix:APP_NAME];
|
||||
consumer = [[OAConsumer alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -49,7 +50,6 @@
|
|||
}
|
||||
|
||||
-(void)requestAToken {
|
||||
consumer = [[OAConsumer alloc] initWithKey:OAUTH_CONSUMER_KEY secret:OAUTH_CONSUMER_SECRET];
|
||||
|
||||
NSURL *url = [NSURL URLWithString:OAUTH_REQUEST_TOKEN_URL];
|
||||
|
||||
|
@ -102,39 +102,26 @@
|
|||
|
||||
[request setHTTPMethod:@"POST"];
|
||||
|
||||
|
||||
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
|
||||
[fetcher fetchDataWithRequest:request
|
||||
delegate:self
|
||||
didFinishSelector:@selector(accessTokenTicket:didFinishWithData:)
|
||||
didFailSelector:@selector(requestTokenTicket:didFailWithError:)];
|
||||
didFailSelector:@selector(accessTokenTicket:didFailWithError:)];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)accessTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
|
||||
NSLog(@"%@", ticket);
|
||||
if (ticket.didSucceed) {
|
||||
NSString *responseBody = [[NSString alloc] initWithData:data
|
||||
encoding:NSUTF8StringEncoding];
|
||||
accessToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
|
||||
|
||||
self.accessToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
|
||||
[accessToken storeInUserDefaultsWithServiceProviderName:OAUTH_SERVICE_NAME prefix:APP_NAME];
|
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc postNotificationName:@"authentificationSucceded" object:self];
|
||||
|
||||
/*
|
||||
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];
|
||||
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
|
||||
consumer:consumer
|
||||
token:accessToken
|
||||
realm:nil
|
||||
signatureProvider:nil];
|
||||
|
||||
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
|
||||
[fetcher fetchDataWithRequest:request
|
||||
delegate:self
|
||||
didFinishSelector:@selector(apiTicket:didFinishWithData:)
|
||||
didFailSelector:@selector(requestTokenTicket:didFailWithError:)];
|
||||
*/
|
||||
[nc postNotificationName:@"authentificationSucceded" object:self];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,6 +133,54 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)accessTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *)error {
|
||||
NSLog(@"ERROR a: %@", error);
|
||||
//[self requestAccessTokenWithPIN:self];
|
||||
//[twitterPINPanel makeKeyAndOrderFront:self];
|
||||
|
||||
//NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?oauth_token=%@", OAUTH_USER_AUTHORIZATION_URL, requestToken.key]];
|
||||
//s[[NSWorkspace sharedWorkspace] openURL:url];
|
||||
}
|
||||
|
||||
- (void)updateTweet:(NSString *)tweet inReplaToStatus:(NSString *)statusId {
|
||||
|
||||
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
|
||||
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
|
||||
consumer:consumer
|
||||
token:accessToken
|
||||
realm:nil
|
||||
signatureProvider:nil];
|
||||
|
||||
OARequestParameter *source = [[OARequestParameter alloc] initWithName:@"source" value:@"twittia"];
|
||||
OARequestParameter *status = [[OARequestParameter alloc] initWithName:@"status" value:tweet];
|
||||
|
||||
NSMutableArray *params = [NSMutableArray arrayWithObjects:source, status, nil];
|
||||
|
||||
if (statusId) {
|
||||
OARequestParameter *reply = [[OARequestParameter alloc] initWithName:@"in_reply_to_status_id" value:statusId];
|
||||
[params addObject:reply];
|
||||
}
|
||||
|
||||
[request setHTTPMethod:@"POST"];
|
||||
[request setParameters:params];
|
||||
|
||||
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
|
||||
[fetcher fetchDataWithRequest:request
|
||||
delegate:self
|
||||
didFinishSelector:@selector(updateTweetTicket:didFinishWithData:)
|
||||
didFailSelector:@selector(updateTweetTokenTicket:didFailWithError:)];
|
||||
}
|
||||
|
||||
- (void)updateTweetTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
|
||||
if (ticket.didSucceed) {
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc postNotificationName:@"getTweetUpdates" object:self];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateTweetTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *)error {
|
||||
NSLog(@"ERROR update tweet: %@", error);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Reference in a new issue