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);
- }
- }];
也很簡單,一樣是個回調,並且是匿名函數。
後邊還沒看。