Tried many ways to fetch photos from Google photos with picasa webalbum and Google drive but i cant achieve the result.Please let me know how to fetch google photos alone and below coding displays only drive like Pdf docs etc but i need photos...Is there is any query i need to implement instead of files or id.The sample coding is based on Mac and there is no proper solution for iOS and everything in XML format please guide me to overcome this.
GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query];
query.fields = @"nextPageToken, files(id, name)";
query.pageSize = 10;
[self.service executeQuery:query
delegate:self
didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
- (void)displayResultWithTicket:(GTLRServiceTicket *)ticket
finishedWithObject:(GTLRDrive_FileList *)result
error:(NSError *)error
{
if (error == nil)
{
NSMutableString *output = [[NSMutableString alloc] init];
if (result.files.count > 0)
{
[output appendString:@"Files:\n"];
int count = 1;
for (GTLRDrive_File *file in result.files)
{
[FileString appendFormat:@"%@ (%@)\n", file.name, file.imageMediaMetadata];
count++;
NSLog(@"PrintFileString %@",file);
}
} else
{
[output appendString:@"No files found."];
}
self.output.text = output;
} else
{
NSMutableString *message = [[NSMutableString alloc] init];
[message appendFormat:@"Error getting presentation data: %@\n", error.localizedDescription];
[self showAlert:@"Error" message:message];
}
}
Ok finally i fetched google photos with Google Drive, hopefully this answer will be useful for someone in future.Many one suggested Picasa but i achieved it with google drive.I will let you know the steps
1)Install Pod
pod 'GoogleAPIClientForREST/Drive', '~> 1.2.1'
ViewController.h
@property (nonatomic, strong) GTLRDriveService *service;
ViewDidLoad
GIDSignIn* signIn = [GIDSignIn sharedInstance];
signIn.delegate = self;
signIn.uiDelegate = self;
signIn.scopes = [NSArray arrayWithObjects:kGTLRAuthScopeDrivePhotosReadonly, nil];
[signIn signInSilently];
// Initialize the service object.
self.service = [[GTLRDriveService alloc] init];
self.service.shouldFetchNextPages = YES;
After making Signin and getting permission it will redirect to this method
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error
{
if (error != nil)
{
self.service.authorizer = nil;
}
else
{
self.service.authorizer = user.authentication.fetcherAuthorizer;
[self listFiles];
}
}
Fetching Photos and storing in NsmutableArray
//Google photos is Nsmutablearray
- (void)listFiles
{
GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query];
query.q = @"mimeType='image/jpeg'";
query.spaces = @"photos";
query.pageSize = 200;
query.fields = @"nextPageToken,files(id,name,mimeType,thumbnailLink,originalFilename)";
[self.service executeQuery:query completionHandler:^(GTLRServiceTicket *ticket,
GTLRDrive_FileList *result,
NSError *error)
{
if (error == nil)
{
[GooglePhotos removeAllObjects];
for (GTLRDrive_File *fileInput in result.files)
{
[SVProgressHUD show];
NSMutableDictionary*Mydiction=[[NSMutableDictionary alloc]init];
[Mydiction setObject:fileInput.thumbnailLink forKey:@"IMAGEURL"];
[Mydiction setObject:fileInput.identifier forKey:@"UNIQUEKEY"];
[Mydiction setObject:fileInput.originalFilename forKey:@"ORIGINALFILENAME"];
[Mydiction setObject:fileInput.name forKey:@"NAME"];
[Mydiction setObject:fileInput.mimeType forKey:@"MIMETYPE"];
[GooglePhotos removeObject:Mydiction];
[GooglePhotos addObject:Mydiction];
// NSLog(@"PrintDetails %@",GooglePhotos);
}
[SVProgressHUD dismiss];
} else
{
NSLog(@"An error occurred: %@", error);
}
}];
}