Tag: GTMOAuth
- (GTMOAuthAuthentication *)authForTwitter { //以下を修正 NSString *myConsumerKey = @"YourConsumerKey"; NSString *myConsumerSecret = @"YourConsumerSecret"; if ([myConsumerKey length] == 0 || [myConsumerSecret length] == 0) { return nil; } GTMOAuthAuthentication *auth; auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 consumerKey:myConsumerKey privateKey:myConsumerSecret] autorelease]; [auth setServiceProvider:kTwitterServiceName]; return auth; }
- (void)signInToTwitter { [self signOut]; NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/request_token"]; NSURL *accessURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"]; NSURL *authorizeURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/authorize"]; GTMOAuthAuthentication *auth = [self authForTwitter]; if (auth == nil) { // perhaps display something friendlier in the UI? NSAssert(NO, @"A valid consumer key and consumer secret are required for signing in to Twitter"); } //これはダミーでいいらしい [auth setCallback:@"http://www.example.com/OAuthCallback"]; NSString *keychainItemName = nil; if ([self shouldSaveInKeychain]) { keychainItemName = kTwitterKeychainItemName; } // Display the autentication view. GTMOAuthViewControllerTouch *viewController; viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:nil //scopeはNULLに language:nil requestTokenURL:requestURL authorizeTokenURL:authorizeURL accessTokenURL:accessURL authentication:auth appServiceName:keychainItemName delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease]; // Cookieを消去するURLこれもhttpsバージョンにしたほうがよいのかな? [viewController setBrowserCookiesURL:[NSURL URLWithString:@"https://api.twitter.com/"]]; [[self navigationController] pushViewController:viewController animated:YES]; }