5

Actually I integrated google-drive-sdk with my ios app. I can able to to upload specified file on google drive through google-drive-sdk for iOS. Additionally I want to provide a functionality for choosing a folder from available folder in which user want to upload that file on Google Drive.

So, I found how to list all files of Google Drive but unable to find how to list of all folders of Google Drive.

I also went through whole API reference on Google Developer site but didn't found any solution about it.

I had found somewhere that using below code folder listing can be done so tried it but it didn't work.

GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = @"mimeType='application/vnd.google-apps.folder' and trashed=false";

[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                                          GTLDriveFileList *files,
                                                          NSError *error) {

    if (error == nil) {
        NSLog(@"Array of folder: %@", files.items);
    } else {
        NSLog(@"An error occurred: %@", error);
    }
}];

So is there any solution for getting list of folders from Google Drive using google-drive-sdk?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Nirav Valera
  • 420
  • 4
  • 13
  • Hey @cultor Did you get the solution for this . If you get please give the answer here . I'm also facing the same problem . I need to list out the folders . – sunil Aug 23 '14 at 11:42

3 Answers3

2

Assuming this code works, there is a problem in the query. Multiple queries should be combined by and.

query.q = @"mimeType='application/vnd.google-apps.folder' and trashed=false";

For more examples of sample queries, take a look at Search for Files in official documentation.

Also, in case this code doesn't work, you want to use Files.list() with query above. Check the link and there is a sample code for Object-c you might want to use.

JunYoung Gwak
  • 2,967
  • 3
  • 21
  • 35
  • hi, thanks for quick response. I tried by adding "and" (@"mimeType='application/vnd.google-apps.folder' and trashed=false"). But still it didn't work. And about this link https://developers.google.com/drive/v2/reference/files/list I already went through it but it's only for listing all files not folders. – Nirav Valera Jun 21 '13 at 05:48
1

What are the scopes you are using? make sure you are using

kGTLAuthScopeDrive = @"https://www.googleapis.com/auth/drive";

example:

NSString *scope = kGTLAuthScopeDrive;

GTMOAuth2ViewControllerTouch *authViewController =
[[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope
                                           clientID:kClientId
                                       clientSecret:kClientSecret
                                   keychainItemName:kKeychainItemName
                                           delegate:self
                                   finishedSelector:finishedSelector];

[self presentViewController:authViewController animated:YES completion:nil];
user02620
  • 349
  • 1
  • 2
  • 6
  • 1
    I agree. You might be using the default scope kGTLAuthScopeDriveFile which will show only files created by your app. https://developers.google.com/drive/web/scopes – Ted Aug 26 '14 at 03:18
0

Use the proper scope.

limited drive.file scope that only allows it to access files that it created or that the user opened with it.

full drive scope that allows the app to manage all user's Drive files.

It is strongly recommended to request the limited scope when possible. For more details about all available scopes, check the Google Drive SDK documentation:

https://developers.google.com/drive/scopes

pkc456
  • 8,350
  • 38
  • 53
  • 109