Can we fetch all the photos from the Google Drive - ios

I am asking a general question, Can i fetch all photos from the Google Drive without Downloading process.I am using a Google Drive SDK and i am very stuck for finding the solution.Any one have experience in google drive sdk. Please share your experience.Thanks for any help.
I want only fetch the Google Drive Photos not download in our application.

You can use Drive's query parameters while using the code snippet on the Querying for Files section of the documentation
I checked the Supported MIME Type section, and you can set the q attribute as
NSString *search = #"mimeType = 'application/vnd.google-apps.photo'";
GTLServiceDrive *drive = ...;
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = search;
[drive executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *fileList,
NSError *error) {
if (error == nil) {
NSLog(#"Have results");
// Iterate over fileList.files array
} else {
NSLog(#"An error occurred: %#", error);
}
}];

Related

Google Drive Api V3 is not returning Web Content link after uploading a new file to Drive?

I am working on google client Api V3 for uploading files from my IOS Application.
The Scopes I have used are
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeDrive,kGTLAuthScopeDriveFile,kGTLAuthScopeDriveAppdata,kGTLAuthScopeDriveMetadata, nil];
The code I used for uploading a new file is
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQuery * query = [GTLQueryDrive queryForFilesCreateWithObject:metadata uploadParameters:uploadParameters];
GTLServiceTicket *uploadTicket=[self.gogService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error) {
if (error == nil) {
NSLog(#"File WebContent Link %#", [updatedFile webViewLink]);
}
else {
NSLog(#"An error occurred: %#", [error localizedDescription]);
}
}];
[uploadTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite)
{
progressBar.progress=(1.0*totalBytesWritten/(1.0*totalBytesExpectedToWrite)) ;
NSLog(#"%llu",totalBytesWritten);
NSLog(#"%llu",totalBytesExpectedToWrite);
}];
The problem is web content link is null and want it in response to store it in my database because my web App will use this link to open that file.
Previous version of google drive api was returning web content link.
How can I get Web Content Link?
Check this documentation: Migrate to Google Drive API v3. Be noted that full resources are no longer returned by default. Use the fields query parameter to request specific fields to be returned. If left unspecified only a subset of commonly used fields are return. You may check this sample for reference.

google drive iOS sdk, can't get file's description field

In my application, I need to get file's description, however, the descriptionProperty was always nil for every file I've got. I did the same thing using google API explorer (the field was the same: items(description, title)), and could get the description successfully.
The code is the following:
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.fields = #"items(description,title)";
[driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLDriveFileList *files, NSError *error) {
if (error == nil) {
NSLog(#"has %d files", [files.items count]);
GTLDriveFile *item;
for (int i = 0; i < files.items.count; i ++) {
item = [files.items objectAtIndex: i];
NSLog(#"%#", item.title);
NSLog(#"%#", item.descriptionProperty);
}
} else {
NSLog(#"An error occurred: %#", error);
}
}];
the log message I've got:
has 19 files
TestFile.txt
(null)
TestFile1.txt
(null)
...
As you can see, I got the title successfully, but the description was null for every file. I also tried not to set query.fields to let it get all fields. In this case, I could successfully get the description. But I really don't want to get all fields cause it's not necessary at all. Does anyone know what caused the problem? Thanks a lot!
Thanks for the report, this is a bug that should be fixed this week.

iOS YouTube "No Filters Selected"

I'm trying to make a request for playListItems using the YouTube iOS SDK.
I'm getting back an error...
Error Domain=com.google.GTLJSONRPCErrorDomain
Code=-32602 "The operation couldn’t be completed. (No filter selected.)"
UserInfo=0x1568f1e0
{
error=No filter selected.,
GTLStructuredError=GTLErrorObject 0x1567fdf0: {message:"No filter selected." code:-32602 data:[1]},
NSLocalizedFailureReason=(No filter selected.)
}
The query I'm using is this...
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.APIKey = #"my key";
// I suspect the problem is here...
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:#"contentDetails"];
query.q = #"playlistId=<The playlist ID>";
GTLServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (!error) {
GTLYouTubePlaylistItemListResponse *playlistItems = object;
for (GTLYouTubePlaylistItem *playlistItem in playlistItems) {
GTLYouTubePlaylistItemContentDetails *details = playlistItem.contentDetails;
NSLog(#"PlaylistItem video ID = %#", details.videoId);
}
} else {
NSLog(#"%#", error);
}
}];
The problem is that the docs for the entire API are useless so there is no example of this being used. I'm having to put it together from the example for the Google Shopping apis and stuff.
Most of the guess work came from here.
Any ideas what I should put in the query.q value? Or if there's something else I'm missing?
OK, I finally found a link that shed some link on this.
The code to use is...
query.playlistId = #"the playlist ID";
Then everything worked :D

How to get the sub-folders of My Drive in Google Drive

Using the following method, I am able to get the sub-folders, but this code retrieves all the folders from the root. For example, if there is a folder in trash also it retrieves that along with folders in My Drive.
My requirement is that, if the folder is not there in the My Drive, then first I should create one and then insert files. My problem is, when I am checking for the folder name, as the folder exist in trash but not in My Drive, I am getting response as folder exists.
Here is my method to retrieve folders.
If anyone has some idea, please let me know.
-(void)getFileListFromSpecifiedParentFolder {
GTLQueryDrive *query2 = [GTLQueryDrive queryForFilesList];
// GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:#"My Drive"];
query2.q = #"";
//or i also use this code
query2.q = #"mimeType = 'application/vnd.google-apps.folder'";
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query2
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveChildList *children, NSError *error) {
NSLog(#"\nGoogle Drive: file count in the folder: %d", children.items.count);
//incase there is no files under this folder then we can avoid the fetching process
if (!children.items.count) {
return ;
}
if (error == nil) {
for (GTLDriveChildReference *child in children) {
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:child.identifier];
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *file,
NSError *error) {
NSLog(#"\nfile name = %# \n file kind %# \n file identifier %#", file.title,file.kind,file.identifier);
}];
}
}
else
[self createFolderForGoogleDriveWithName:#"Music"];
}];
}
You can filter out trashed directories with the following query: application/vnd.google-apps.folder' and trashed = false

listing all files from specified folders in Google Drive through IOS Google Drive SDK

Actually i integrated google drive sdk with my ios app. I can able to retrieve/upload the files in google drive through google drive ios sdk. But the retrieving files list from specified parent folder taking so much time.
Here the steps and the code which was i am using.
First am getting the children's of the specified parent folder then am getting the GTLDriveChildReference of each child then
then am querying with the child reference identifier.
This is huge process for me. Also it request google server each time. Any better way there to just pass the parent folder id in a query and pulling the files from that parent folder.
-(void)getFileListFromSpecifiedParentFolder {
GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:<some_id or root>];
query2.maxResults = 1000;
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query2
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveChildList *children, NSError *error) {
NSLog(#"\nGoogle Drive: file count in the folder: %d", children.items.count);
//incase there is no files under this folder then we can avoid the fetching process
if (!children.items.count) {
return ;
}
if (error == nil) {
for (GTLDriveChildReference *child in children) {
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:child.identifier];
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *file,
NSError *error) {
NSLog(#"\nfile name = %#", file.originalFilename);
}];
}
}
}];
}
Any help that might be appreciated.
I've been using the following code (which only requires one query rather than multiple queries):
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = [NSString stringWithFormat:#"'%#' IN parents", <the folderID>];
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error) {
...
}];
Seems to be working well thus far.
Try combining queries in a batch query, like
GTLBatchQuery *batchQuery = [GTLBatchQuery batchQuery];
for (GTLDriveChildReference *child in children) {
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:child.identifier];
query.completionBlock = ^(GTLServiceTicket *ticket, GTLDriveFile *file, NSError *error) {
NSLog(#"error=%#, file name = %#", error, file.title);
};
[batchQuery addQuery:query];
}
[driveService executeQuery:batchQuery completionHandler:...]
If automatic fetching of result pages is enabled (service.shouldFetchNextPages = YES) then try to set the maxResults property of queries to avoid the need for the library to make multiple fetches. For example, if there are 100 or fewer results for a query, a maxResults value of 100 will retrieve them with a single fetch.
Requests for partial responses are also a bit faster and use much less memory, particularly for large results.
Look at http logs for a better idea of the response sizes for your queries.

Resources