Google Drive MIME types iOS - ios

I'm trying to integrate Google Drive API with my iOS application. I'm unable to download files, however, and I think it has to do with the MIME type. In the API console I set the MIME types like so:
And I download files with the following code:
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = #"mimeType = 'text/plain'";
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error) {
if (error == nil) {
if (self.googleDriveFiles == nil) {
self.googleDriveFiles = [[NSMutableArray alloc] init];
}
[self.googleDriveFiles removeAllObjects];
[self.googleDriveFiles addObjectsFromArray:files.items];
NSLog(#"files: %#",self.googleDriveFiles);
[self.noteTableview reloadData];
} else {
NSLog(#"An error occurred: %#", error);
//[DrEditUtilities showErrorMessageWithTitle:#"Unable to load files"
// message:[error description]
// delegate:self];
}
}];
NSLog outputs (null) What's wrong here?

Related

Finding the owner of a shared folder Google Drive

After looking and finding for a shared folder that matches a given name, I need to know if that folder's creator/owner is a specific google account. How could I achieve that utilizing Google Drive's Objective-C SDK.
Here is my query that finds the shared folder given its name:
GTLQueryDrive *queryDrive = [GTLQueryDrive queryForFilesList];
queryDrive.q = #"mimeType='application/vnd.google-apps.folder' and trashed=false";
[self.service executeQuery:queryDrive completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error) {
if (error == nil)
{
NSString *identifier = #"";
for(GTLDriveFile *file in files.files)
{
NSArray *tempArray = [NSArray arrayWithArray:file.owners];
NSLog(#"File Title: %# | ID: %#",file.name , file.identifier);
if ([file.name isEqualToString:#"GIVEN FOLDER NAME"]) {
identifier = file.identifier;
//How to know if the found folder is owned by a specified email?
break;
}
}
if ([identifier isEqualToString:#""]) {
[UISpinningWheelController removeSpinningWheel:self.view];
[self showAlertWithTitle:#"Error" andMessage:#"The required folder has not been shared with this Google account. Please contact the administrator."];
}
}
else {
[UISpinningWheelController removeSpinningWheel:self.view];
[self showAlertWithTitle:#"Error" andMessage:[error localizedDescription]];
}
}];
Thank you so much for your help.

download-url of GTLDriveFile coming nil and even GTLDriveFileExportLinks coming nil

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

youtube api v3-ios: How do I allow user to report a youtube video as inappropriate?

In YouTube v2, user can report a video as inappropriate through following way,
-(void)flagInappropriateVideo: (NSString*)inVideoId
{
GDataServiceGoogleYouTube *service = [self youtubeService];
[service fetchEntryWithURL:videoEntryFetchURL completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) {
NSError *err = error;
NSURL *complaintsLink = [[(GDataEntryYouTubeVideo*)entry complaintsLink] URL];
if(err || !entry || !complaintsLink)
{
if(!err)
err = [NSError errorWithDomain: UNKNOWN_ERROR_DOMAIN code: UNKNOWN_ERROR_CODE userInfo: nil];
}
else
{
GDataEntryYouTubeComplaint *complaint = [GDataEntryYouTubeComplaint complaintEntry];
[service fetchEntryByInsertingEntry:complaint
forFeedURL: complaintsLink
delegate:self
didFinishSelector:#selector(complaintTicket:finishedWithEntry:error:)];
}
}];
}
- (void)complaintTicket:(GDataServiceTicket *)ticket
finishedWithEntry:(GDataEntryBase *)entry
error:(NSError *)error
{
// handle completion
}
I did not find any equivalent classes and methods for GDataEntryYouTubeVideo and complaintsLink also the GDataEntryYouTubeComplaint to report a complaintEntry in YouTube V3.
I would like to know whether this is depreciated or is there any other way to do this? Please do help,Thanks!
You can see them from GDataObjectiveC client.

Getting user detail, when login from google in iOS application

I am using google login in my project i have successfully login but did not got the user detail.
i have use code from this link
https://developers.google.com/+/mobile/ios/sign-in
an fetch the value from
https://developers.google.com/+/mobile/ios/people
this code for login and getting user email id and circle people:
[GPPSignIn sharedInstance].clientID = kClientId;
//[GPPSignIn sharedInstance].scopes= [NSArray arrayWithObjects:kGTLAuthScopePlusLogin, nil];
[GPPSignIn sharedInstance].shouldFetchGoogleUserID=YES;
[GPPSignIn sharedInstance].shouldFetchGoogleUserEmail=YES;
[GPPSignIn sharedInstance].delegate=self;
[[GPPSignIn sharedInstance] authenticate];
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
plusService.retryEnabled = YES;
// [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
GTLQueryPlus *query =
[GTLQueryPlus queryForPeopleListWithUserId:#"me"
collection:kGTLPlusCollectionVisible];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPeopleFeed *peopleFeed,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
} else {
// Get an array of people from GTLPlusPeopleFeed
NSArray* peopleList = peopleFeed.items ;
NSLog(#"People list =%#",peopleList);
}
}];
NSLog(#"email =%#", signIn .authentication.userEmail);
}
but get these error in console
BarberBlue[3611/0x1051a7310] [lvl=3] __27-[LoginVC loginWithgoogle:]_block_invoke() Error: Error Domain=com.google.GTLJSONRPCErrorDomain Code=403 "The operation couldn’t be completed. (Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.)" UserInfo=0x10c91cf90 {error=Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup., NSLocalizedFailureReason=(Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.), GTLStructuredError=GTLErrorObject 0x10c91e490: {message:"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." data:[1] code:403}
}
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
plusService.retryEnabled = YES;
GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:#"me"];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPerson *person,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
} else {
NSString *description = [NSString stringWithFormat:
#"%#\n%#", person.displayName,
person.name];
NSLog(#"User Detail : %#" ,description);
}
}];
I am also faced same problem, this method solved that. Using above code you will get the user detail.
To get User Details do the following :
GTLPlusPerson *person = [GPPSignIn sharedInstance].googlePlusUser;
if (person == nil) {
return;
}
NSLog(#"Person : %#" ,person);

objective c list files from google drive

Am developing ios app including google drive. In google drive when am trying to list files, it displays all folders, subfolders, subfiles in single page itself. These is my code
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
[driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *filesList,
NSError *error) {
if (error == nil) {
[FilesFromGoogleDrive addObjectsFromArray:filesList.items
];
};
I dont want to list all files in main page. I need similar to google drive application for accessing folders, subfolders, subfiles in sequential way.Am trying this from past one week but there is no good result. So please help me how to access folders, subfolders.
If you want to list all files in a folder identified by folderId, you can use the following code (from https://developers.google.com/drive/v2/reference/children/list):
+ (void)printFilesInFolderWithService:(GTLServiceDrive *)service
folderId:(NSString *)folderId {
// The service can be set to automatically fetch all pages of the result. More
// information can be found on https://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Result_Pages.
service.shouldFetchNextPages = YES;
GTLQueryDrive *query =
[GTLQueryDrive queryForChildrenListWithFolderId:folderId];
// queryTicket can be used to track the status of the request.
GTLServiceTicket *queryTicket =
[service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveChildList *children, NSError *error) {
if (error == nil) {
for (GTLDriveChildReference *child in children) {
NSLog(#"File Id: %#", child.identifier);
}
} else {
NSLog(#"An error occurred: %#", error);
}
}];
}
Another option is to search for files having folderId in their Parents collection:
https://developers.google.com/drive/search-parameters
For instance, you can have a search query like the following:
'1234567' in parents
Where '1234567' is the id of the folder you want to list files for.
I hope this is one that you want. Just use this code this one will give you what do you need.
-(void)getFileListFromSpecifiedParentFolder {
GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:<some_folder_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);
}];
}
}
}];
}
Here is how I did it:
NSString* currentFolderID = #"root";//folder id for the Google Drive root directory
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
NSString* queryQ = [NSString stringWithFormat: #"trashed = false and '%#' in parents", currentFolderID];
query.q = queryQ;
[_googleService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error)
{
if (error == nil)
{
[self listFiles: files.items];
}
Use #"root" as the parent to list files from the root directory, and use file.identifier of the subfolder item as the parent to list files from. To query files from a subfolder, use the following 2 lines to get the parent identifier for all files in the subfolder.
GTLDriveFile subFolderItem;
currentFolderID = subFolderItem.identifier;
To fetch the list of all files of Google Drive, use below code:
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = [NSString stringWithFormat:#"'%#' IN parents", #"root"];
[self.serviceDrive executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error) {
if (error == nil)
{
NSMutableArray * driveFiles = [[NSMutableArray alloc] init];
[driveFiles addObjectsFromArray:files.items];
for (GTLDriveFile *file in driveFiles)
NSLog(#"File is %#", file.title);
}
else
{
NSLog(#"An error occurred: %#", error);
}
}];

Resources