我跟着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