google objective-c client library (docs & spreadsheets)

http://code.google.com/p/gdata-objectivec-client/source/checkout

 svn地址:

svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/ gdata-objectivec-client-read-only

可以直接输入这个命令在mac os下会自动下载,你需要先cd进一个安装目录,也可以用svn软件辅助。

1. 可以打开docsSample工程来学习,这个项目有依赖选项,它依赖于GData.xcode它的framework.新建工程的时候要注意这点

2.它默认是x86版本的power pc编译选项,这一点自行修改,否则引用它的framework的时候会出错。

 

已知的功能实现:

1.这个库大量使用匿名函数异步回调,这是个好现像。

  
  
  
  
  1. NSString *scope = [GTMOAuth2Authentication scopeWithStrings: 
  2.                        [GDataServiceGoogleDocs authorizationScope], 
  3.                        [GDataServiceGoogleSpreadsheet authorizationScope], 
  4.                        nil]; 
  5.      
  6.     NSBundle *frameworkBundle = [NSBundle bundleForClass:[GTMOAuth2WindowController class]]; 
  7.     GTMOAuth2WindowController *windowController; 
  8.     windowController = [GTMOAuth2WindowController controllerWithScope:scope 
  9.                                                              clientID:self.clientID 
  10.                                                          clientSecret:self.clientSecret 
  11.                                                      keychainItemName:@"google docs : dante lee" 
  12.                                                        resourceBundle:frameworkBundle]; 
  13.      
  14.     //[windowController setUserData:NSStringFromSelector(signInDoneSel)]; 
  15.     [windowController signInSheetModalForWindow:[self window] 
  16.                               completionHandler:^(GTMOAuth2Authentication *auth, NSError *error)  
  17.                                 { 
  18.                                   // callback 
  19.                                   if (error == nil)  
  20.                                   { 
  21.                                       [[self docsService] setAuthorizer:auth]; 
  22.                                       NSLog(@"%@",[[auth parameters] objectForKey:@"access_token"]); 
  23.                                       GTMOAuth2Authentication * authorization = (GTMOAuth2Authentication*)[(GDataServiceGoogleDocs*)self.docsService authorizer]; 
  24.                                       self.txt_authToken.stringValue = [authorization.parameters objectForKey:@"refresh_token"]; 
  25.                                       NSString *selStr = [windowController userData]; 
  26.                                       if (selStr)  
  27.                                       { 
  28.                                           [self performSelector:NSSelectorFromString(selStr)]; 
  29.                                       } 
  30.                                   }  
  31.                                   else  
  32.                                   { 
  33.                                       //[self setDocListFetchError:error]; 
  34.                                       //[self updateUI]; 
  35.                                   } 
  36.                               }]; 

实现登录的核心代码,其内部都已经实现好了,如果去看库的话,库里还有xib文件,就是说这个登录窗口给你做好了,拿着用就行了。

2.GDataEntryDocListMetadata是存储用户信息的类

获取用户信息的方法:

 

  
  
  
  
  1. NSURL *entryURL = [GDataServiceGoogleDocs metadataEntryURLForUserID:kGDataServiceDefaultUser]; 
  2. GDataServiceGoogleDocs *service = [self docsService]; 
  3. [service fetchEntryWithURL:entryURL 
  4.          completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) { 
  5.              // callback 
  6.              //[self setMetadataEntry:(GDataEntryDocListMetadata *)entry]; 
  7.              self.txt_authToken.stringValue = ((GDataEntryDocListMetadata*)entry).quotaBytesTotal.stringValue; 
  8.              // enable or disable features 
  9.              //[self updateUI]; 
  10.               
  11.              if (error != nil) { 
  12.                  NSLog(@"Error fetching user metadata: %@", error); 
  13.              } 
  14.          }]; 

也很简单,同样是个回调,而且是匿名函数。

后边还没看。

你可能感兴趣的:(Google,client,library,nil)