2012-01-27 47 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文件複製到應用程序的資源文件夾中,以便它可以加載它們。