http://code.google.com/p/gdata-objectivec-client/source/checkoutxcode
svn地址:异步
svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/ gdata-objectivec-client-read-onlyide
能够直接输入这个命令在mac os下会自动下载,你须要先cd进一个安装目录,也能够用svn软件辅助。svn
1. 能够打开docsSample工程来学习,这个项目有依赖选项,它依赖于GData.xcode它的framework.新建工程的时候要注意这点函数
2.它默认是x86版本的power pc编译选项,这一点自行修改,不然引用它的framework的时候会出错。学习
已知的功能实现:fetch
1.这个库大量使用匿名函数异步回调,这是个好现像。google
- NSString *scope = [GTMOAuth2Authentication scopeWithStrings:
- [GDataServiceGoogleDocs authorizationScope],
- [GDataServiceGoogleSpreadsheet authorizationScope],
- nil];
- NSBundle *frameworkBundle = [NSBundle bundleForClass:[GTMOAuth2WindowController class]];
- GTMOAuth2WindowController *windowController;
- windowController = [GTMOAuth2WindowController controllerWithScope:scope
- clientID:self.clientID
- clientSecret:self.clientSecret
- keychainItemName:@"google docs : dante lee"
- resourceBundle:frameworkBundle];
- //[windowController setUserData:NSStringFromSelector(signInDoneSel)];
- [windowController signInSheetModalForWindow:[self window]
- completionHandler:^(GTMOAuth2Authentication *auth, NSError *error)
- {
- // callback
- if (error == nil)
- {
- [[self docsService] setAuthorizer:auth];
- NSLog(@"%@",[[auth parameters] objectForKey:@"access_token"]);
- GTMOAuth2Authentication * authorization = (GTMOAuth2Authentication*)[(GDataServiceGoogleDocs*)self.docsService authorizer];
- self.txt_authToken.stringValue = [authorization.parameters objectForKey:@"refresh_token"];
- NSString *selStr = [windowController userData];
- if (selStr)
- {
- [self performSelector:NSSelectorFromString(selStr)];
- }
- }
- else
- {
- //[self setDocListFetchError:error];
- //[self updateUI];
- }
- }];
实现登陆的核心代码,其内部都已经实现好了,若是去看库的话,库里还有xib文件,就是说这个登陆窗口给你作好了,拿着用就好了。spa
2.GDataEntryDocListMetadata是存储用户信息的类code
获取用户信息的方法:
- NSURL *entryURL = [GDataServiceGoogleDocs metadataEntryURLForUserID:kGDataServiceDefaultUser];
- GDataServiceGoogleDocs *service = [self docsService];
- [service fetchEntryWithURL:entryURL
- completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) {
- // callback
- //[self setMetadataEntry:(GDataEntryDocListMetadata *)entry];
- self.txt_authToken.stringValue = ((GDataEntryDocListMetadata*)entry).quotaBytesTotal.stringValue;
- // enable or disable features
- //[self updateUI];
- if (error != nil) {
- NSLog(@"Error fetching user metadata: %@", error);
- }
- }];
也很简单,一样是个回调,并且是匿名函数。
后边还没看。