google objective-c client library (docs & spreadsheets)

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

  
  
  
  
  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文件,就是說這個登陸窗口給你作好了,拿着用就好了。spa

2.GDataEntryDocListMetadata是存儲用戶信息的類code

獲取用戶信息的方法:

 

  
  
  
  
  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.          }]; 

也很簡單,一樣是個回調,並且是匿名函數。

後邊還沒看。

相關文章
相關標籤/搜索