从谷歌照片中获取照片目标c [iOS] [英] Fetching Photos from google photos Objective c [iOS]

查看:186
本文介绍了从谷歌照片中获取照片目标c [iOS]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试了很多方法来使用picasa webalbum和Google驱动器从Google照片中获取照片,但我无法实现结果。请让我知道如何单独获取谷歌照片以及下面的编码显示只有驱动器像Pdf文档等但我需要照片。 ..是否有任何查询我需要实现而不是文件或id。示例编码基于Mac,没有适当的iOS解决方案,XML格式的所有内容请指导我克服这一点。

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];
    }
}


推荐答案

好的最后我用Google云端硬盘获取谷歌照片,希望这个答案对将来有用的人有用。很多人建议使用Picasa,但我用谷歌驱动器实现了它。我会告诉你步骤

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

pod 'GoogleAPIClientForREST/Drive', '~> 1.2.1'



ViewController.h



ViewController.h

@property (nonatomic, strong) GTLRDriveService *service;



ViewDidLoad



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];
    }
}



获取照片并存储在NsmutableArray中



// Google照片是Nsmutablearray

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);
         }
     }];
}

这篇关于从谷歌照片中获取照片目标c [iOS]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆