2012-01-27 44 views
2

我跟着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; 
} 
+1

只要你知道。在你的代码示例中,你的clientSecret对我们所有人都是可见的。如果您在生产中使用此代码(我不希望),您可能需要重置密钥 – mkral 2012-06-21 15:28:45

回答

1

我解决了这个问题,通过直接添加的GData和OAuth LIB类我的应用程序

+0

我遇到了同样的问题,请问您可以详细了解一下吗?谢谢。 – kevlar 2012-03-25 04:43:11

+0

嗨爆炸可以ü请帮助我使用Gdata从Gmail帐户获取朋友的电子邮件ID。我已经通过谷歌gdata文档,这是非常混乱和复杂。你可以请建议一个好的教程或一些帮助来解决我的问题。提前致谢 – 2012-08-28 12:00:11

0

我有这个相同的问题,必须包括GTMOAuth2ViewControllerTouch.xib文件到我的主要解决方案否则,使用静态库工作得很好。

似乎必须将.xib文件复制到应用程序的资源文件夹中,以便它可以加载它们。