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.
Related
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);
}
}];
I want to download the files from google-drive. I have fetched the GTLDriveFile objects from a drive. But downloadUrl property of these file objects are nil.
Googling more, i got that file.exportLinks also has download links. But that is also coming nil.
I used this code to fetch files:
- (void)fetchFiles {
GTLQueryDrive *query =
[GTLQueryDrive queryForFilesList];
query.maxResults = 10;
[self.service executeQuery:query
delegate:self
didFinishSelector:#selector(displayResultWithTicket:finishedWithObject:error:)];
}
- (void)displayResultWithTicket:(GTLServiceTicket *)ticket
finishedWithObject:(GTLDriveFileList *)files
error:(NSError *)error {
if (error == nil) {
if (files.items.count > 0) {
fileArr=files.items;
}
}
}
here fileArr has the files of class GTLFileDrive.
From Google-drive developer site, i got the following code snippet to download file using a parameter Url:
GTMHTTPFetcher *fetcher = [self.service.fetcherService fetcherWithURLString: urlOfFile];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
// Do something with data
} else {
NSLog(#"An error occurred: %#", error);
}
}];
I need the urlOfFile to complete the task.
Any help would be greatly appreciated.
When you do your initial auth, you need to request the right scope - otherwise, you only get rights to list the files, and not download them.
Something like.
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeDrive, nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:#" "]
clientID:self.clientId
clientSecret:self.clientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
You can see this all in my new Google Drive Picker
https://github.com/ConfusedVorlon/HSGoogleDrivePicker
I'm trying to use the iOS-GTLYouTube library for displaying videos. So far this is what I've got:
//Get the youtube video list
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
// Set the APIKey
service.APIKey = #"APIKey";
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosListWithIdentifier:[vidListIds copy] part:#"id,snippet"];
GTLServiceTicket *ticket = [ service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error)
{
// This callback block is run when the fetch completes
if (error == nil)
{
GTLYouTubeVideoListResponse *products = object;
// iteration of items and subscript access to items.
for (GTLYouTubeVideo *item in products)
{
GTLYouTubeVideoSnippetThumbnails *thumbnails = item.snippet.thumbnails;
[thumbnailMutableList addObject:thumbnails];
NSLog(#"Title: %#", item.snippet.title);
}
}
else
{
NSLog(#"Error: %#", error.description);
}
}];
I don't know why but this code didn't seem to do anything. There's neither the "Title:" log nor the "Error" log. I know that it was done in a separate thread so it worked asynchronously. But I've waited for 1-2 minutes and still nothing is shown. Can anybody help me here? Thanks.
Never mind. In the NSMutableString *vidListIds I forgot to append a comma. Silly me. Thanks for reading though. Sorry for the false alarm. :)
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
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