Code Reference Library: https://github.com/google/google-api-objectivec-client-for-rest
A method for querying Google Drive services.
- (GTLRDriveService *)driveService {
static GTLRDriveService *service;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
service = [[GTLRDriveService alloc] init];
service.shouldFetchNextPages = YES;
service.retryEnabled = YES;
});
return service;
}
After Google Authentication, authorize driveService using the following lines:
In your case
if (authState) {
GTMAppAuthFetcherAuthorization *gtmAuthorization =
[[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];
strongSelf.driveService.authorizer = gtmAuthorization;
[GTMAppAuthFetcherAuthorization saveAuthorization:gtmAuthorization
toKeychainForName:kKeychainItemName];
[self fetchFileList];
}
Then you can use the method below to extract files from Google Drive:
- (void)fetchFileList {
__block GTLRDrive_FileList *fileListNew = nil;
GTLRDriveService *service = self.driveService;
GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query];
query.fields = @"kind,nextPageToken,files(mimeType,id,kind,name,webViewLink,thumbnailLink,trashed)";
GTLRServiceTicket *fileListTicket;
fileListTicket = [service executeQuery:query
completionHandler:^(GTLRServiceTicket *callbackTicket,
GTLRDrive_FileList *fileList,
NSError *callbackError) {
fileListNew = fileList;
}];
}
Try DriveSample from the help library, include the GTLRDrive files in your project, and you are ready to use the method described above.
GTMAppAuthFetcherAuthorization, "GTMAppAuth" .
DriveSample , .