2

I'm working on a Google Drive integration for iOS and I've hit a snag—I need to check for the existence of a file in a folder, but I keep getting a "500 Internal Error" response no matter how I seem to put together the request. I think this should be legit:

// self.directoryDriveFile.identifier is a valid folder identifier retrieved on previous request
GTLQueryDrive *query = [GTLQueryDrive queryForChildrenListWithFolderId:self.directoryDriveFile.identifier];

// add query to specify the file we're interested in (works in Java version...)
query.q = [NSString stringWithFormat:@"title='%@' and trashed=false",
           ZTCloudSyncLockFileName];
// stopping in debugger shows query.q: title='sync.lock' and trashed=false

// fire off request
[self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket,
                                  GTLDriveFileList *files,
                                  NSError *error) {
                  if (error == nil) {
                      if ([files.items count] > 0) {
                          self.foundLockfile = YES;
                      } else {
                          self.foundLockfile = NO;
                      }
                  } else {
                      DLog(@"An error occurred loading lockfile request: %@", error);
                      [self bailWithError:error performCleanup:NO];
                  }
              }];

When the query is executed, it always ends up in error, with the following unfortunately sparse error information:

Error Domain=com.google.GTLJSONRPC
ErrorDomain Code=500 "The operation couldn’t be completed. (Internal Error)" 
UserInfo=0x99c4660 {
  error=Internal Error, 
  GTLStructuredError=GTLErrorObject 0x99c4360: {
  message:"Internal Error" code:500 data:[1]}, 
  NSLocalizedFailureReason=(Internal Error)}

I've also tried the following more basic query, specifying a parents clause, but I end up with the same unfortunately spare error object shown above:

GTLQueryDrive *altQuery = [GTLQueryDrive queryForFilesList];
altQuery.q = [NSString stringWithFormat:@"title='%@' and trashed=false and '%@' in parents",
              ZTCloudSyncLockFileName,
              self.directoryDriveFile.identifier];

That, too, should work, but also produces a 500 error.


Additional information: tested the following while working on this:

  • Check for folder in directory root—OK
  • Create folder in directory root—OK
  • Check for file named sync.lock in directory root—OK
MPelletier
  • 16,256
  • 15
  • 86
  • 137
Billy Gray
  • 1,747
  • 4
  • 18
  • 23
  • Are you using a service account? see:http://stackoverflow.com/questions/13693617/error-500-when-performing-a-query-with-drive-file-scope – Jasper Duizendstra Feb 26 '13 at 17:48
  • I don't know what you mean. Took a look at the link, but it didn't explain "service account." I'm using the API in the way described in the getting started obj-c tutorial and the other examples. – Billy Gray Feb 26 '13 at 18:09
  • @BillyGray you should include the targeted person for your comment like I do, else he will not be notified and possibly won't come back to respond to your comment. – ilmiacs Feb 26 '13 at 21:27
  • @ilmiacs thanks for the tip! Too bad there's no autocomplete for that on the mobile site (at the moment anyway). Cheers. – Billy Gray Feb 27 '13 at 16:15
  • Looks like this might be a bug related to the title query combined with the drive.file scope, not the objective-c code (which looks fine) – Steve Bazyl Feb 27 '13 at 21:05

1 Answers1

0
-(void)fetchGoogleDriveFileListWithfolderId:(NSString *)folderId
    :(void (^)(NSMutableArray *, NSError*))completionBlock
{
    GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
    query.q =[NSString stringWithFormat:@"'%@' in parents and trashed=false", folderId];

    GTLServiceTicket *ticketListing = [self.driveService
        executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files, NSError *error)
    {
        NSMutableArray *mainArray=[[NSMutableArray alloc]init];

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

You can use above method for fetch the folder contents. Here folderId is

  • “root” (Main Drive)
  • “sharedWithMe” for shared folder
  • GTLDrivefile identifier value
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90
Adarsh G J
  • 2,684
  • 1
  • 24
  • 25