我跟着this blog設置的GData我的ios項目,建造成功,一切正常,但是當我添加GTMOAuth2ViewControllerTouch以我的窗口,它只是秀沒有任何東西的黑色視圖。在我的項目中構建GTMOAuth2ViewControllerTouch的代碼是從http://code.google.com/p/gtm-oauth2/複製的。在gtm-oauth2項目中,OAuth是工作的,我不知道爲什麼相同的代碼不能在我的新項目中工作。在xcode4設置的GData IOS客戶端後,不能使用OAuth
我的代碼:
GDAppDelegate.h:
@interface GDAppDelegate : UIResponder <UIApplicationDelegate>{
@private
UIWindow *_window;
UINavigationController *mNavigationController;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) GDViewController *viewController;
@end
GDAppDelegate.m:
#import "GDAppDelegate.h"
#import "GData.h"
#import "GTMOAuth2SignIn.h"
#import "GTMOAuth2ViewControllerTouch.h"
@implementation GDAppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:nil];
mainNavigationController.view.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-20);
[mainNavigationController.navigationBar setBarStyle:UIBarStyleDefault];
[mainNavigationController setToolbarHidden:YES];
NSString *keychainItemName = nil;
NSString *scope = @"https://www.googleapis.com/auth/plus.me";
NSString *clientID = @"181779079861.apps.googleusercontent.com";//self.clientIDField.text;
NSString *clientSecret = @"FAIi_4YiI3vAtYi7Xf1nMF7Q";//self.clientSecretField.text;
SEL finishedSel = @selector(viewController:finishedWithAuth:error:);
GTMOAuth2ViewControllerTouch *viewController;
viewController = [GTMOAuth2ViewControllerTouch controllerWithScope:scope
clientID:clientID
clientSecret:clientSecret
keychainItemName:keychainItemName
delegate:self
finishedSelector:finishedSel];
NSDictionary *params = [NSDictionary dictionaryWithObject:@"en"
forKey:@"hl"];
viewController.signIn.additionalAuthorizationParameters = params;
NSString *html = @"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
viewController.initialHTMLString = html;
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
只要你知道。在你的代碼示例中,你的clientSecret對我們所有人都是可見的。如果您在生產中使用此代碼(我不希望),您可能需要重置密鑰 – mkral 2012-06-21 15:28:45