2012-07-04 2 views
3

oauth 2.0 프로토콜을 사용하여 Google 문서 도구에 연결하려고합니다. 내가 액세스 토큰을 얻을 때문에 연결이 괜찮다고 생각합니다. 그 후에 나는 그 서류들을 열거하고 싶다. 내 프로젝트에 objective-c API를위한 gdata를 추가했고 예제를 따라했지만 어떤 문서도 얻지 못하고있다. 나는 그저 firt의 doc 제목을 읽고 그것을 보여 주려고 노력하고 있지만, 어떤 것이 틀렸거나 뭔가를 놓치고있을 수도 있습니다. 어떤 도움이 필요합니까? 감사. 여기에 코드입니다 :oauth 및 gdata objective-c api를 사용하여 Google 문서를 열거하려고합니다

ViewController.m

@implementation ViewController 

@synthesize accessToken; 
@synthesize mDocListFeed; 
@synthesize mDoclistFetchTicket; 


static NSString *const kMyClientID = @"199740745364-22lugf8undgv0rc0ucbfpgsn3v90lfsd.apps.googleusercontent.com"; 
static NSString *const kMyClientSecret = @"dPFs5D66kLyQIgUNL6igKUoX"; 
static NSString *const kKeychainItemName = @"casa"; 

- (GDataServiceGoogleDocs *)docsService { 

    static GDataServiceGoogleDocs* service = nil; 

    if (!service) { 
    service = [[GDataServiceGoogleDocs alloc] init]; 

    [service setShouldCacheResponseData:YES]; 
    [service setServiceShouldFollowNextLinks:YES]; 
    [service setIsServiceRetryEnabled:YES]; 
} 

return service; 

} 



- (void) mifetch { 

    GDataServiceGoogleDocs *service = [self docsService]; 

    GDataServiceTicket *ticket; 


    NSURL *feedURL = [GDataServiceGoogleDocs docsFeedURL]; 


    ticket = [service fetchFeedWithURL:feedURL 
       delegate:self 
     didFinishSelector:@selector(ticket:finishedWithFeed:error:)]; 

    mDoclistFetchTicket = ticket; 

} 

- (void) ticket: (GDataServiceTicket *) ticket 
     finishedWithFeed: (GDataFeedDocList *) feed 
      error: (NSError *) error { 

mDocListFeed = feed; 


GDataEntryDocBase *doc = [[mDocListFeed entries] objectAtIndex:0]; 

NSString *ttitle = [[doc title] stringValue]; 
UIAlertView *alertView = [ [UIAlertView alloc] initWithTitle:@"primer doc" 
            message:[NSString stringWithFormat:@"titulo: %@", ttitle] 
                delegate:self 
              cancelButtonTitle:@"Dismiss" 
              otherButtonTitles:nil]; 

[alertView show]; 

} 


- (void)authorize { 

    NSString *scope = @"https://spreadsheets.google.com/feeds"; 

// scope for Google+ API 

GTMOAuth2ViewControllerTouch *windowController = [[GTMOAuth2ViewControllerTouch alloc]  initWithScope:scope 
                          clientID:kMyClientID 
                         clientSecret:kMyClientSecret 
                        keychainItemName:kKeychainItemName 
                          delegate:self 
                finishedSelector:@selector(viewController:finishedWithAuth:error:)]; 


[[self navigationController] pushViewController:windowController animated:YES]; 
} 


- (IBAction)autenticarse 
{ 
[self authorize]; 
} 


- (IBAction)listar 
{ 

[self mifetch]; 
} 


- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController 
    finishedWithAuth:(GTMOAuth2Authentication *)auth 
      error:(NSError *)error 
{ 


if (error != nil) 
{ 
    // Authentication failed 
    UIAlertView *alertView = [ [UIAlertView alloc] initWithTitle:@"Authorization Failed" 
                 message:[error localizedDescription] 
                 delegate:self 
               cancelButtonTitle:@"Dismiss" 
               otherButtonTitles:nil]; 
    [alertView show]; 
} 
else 
{ 
    //si error==nil en el callback, entonces la peticion fue autorizada 
    // Authentication succeeded 

    // Assign the access token to the instance property for later use 
    self.accessToken = auth.accessToken; 



    // Display the access token to the user 
    UIAlertView *alertView = [ [UIAlertView alloc] initWithTitle:@"Authorization Succeeded" 
    message:[NSString stringWithFormat:@"Access Token: %@ code:%@", auth.accessToken, auth.code] 
                 delegate:self 
               cancelButtonTitle:@"Dismiss" 
               otherButtonTitles:nil]; 
    [alertView show]; 
    [[self docsService] setAuthorizer:auth]; 

} 
} 


// table view data source methods 


//The first thing we have to do is, tell the table view how many rows it should expect and this is done in tableView:numberOfRowsInSection. 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

if (tableView == tablalistar) { 
    return [[mDocListFeed entries] count]; 
} 

return 0; 


} 


//Now that the table view knows how many rows to display, we need to display the actual text which goes in a table view cell. The table view is made of table rows and rows contains table cell. This is done in tableView:cellForRowAtIndexPath which is called n number of times, where n is the value returned in tableView:numberOfRowsInSection. The method provides indexPath which is of type NSIndexPath and using this we can find out the current row number the table view is going to display. 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 


UITableViewCell *cell = [tableView 
         dequeueReusableCellWithIdentifier:@"tablalistar"]; 

if (tableView == tablalistar) { 



    GDataEntryDocBase *doc = [[mDocListFeed entries] objectAtIndex:indexPath.row]; 

    cell.textLabel.text = [[doc title] stringValue]; 


} 
return cell; 
} 




@end 

감사합니다!

+0

콘솔에 오류가 있습니까? – Lvsti

답변

1

범위 문자열이 스프레드 시트 API에 대해서만 권한을 요청하고 있지만 가져 오기는 문서 목록 API에 대한 것입니다. 여러 서비스 +[GDataServiceGoogleDocs authorizationScope]

스코프는 또한, API의 문서 목록이 Google Drive API로 대체되었다 +[GTMOAuth2Authentication scopeWithStrings:]

과 결합 될 수있는 한 문서 목록에 대한 API

범위가 가능하다.

+0

정말 고마워요 !!!! 그것은 작동한다! !!! – user1502091