Google云端硬盘iOS SDK文件thumbnailLink因404错误而失败

时间:2013-12-03 00:57:17

标签: ios http-status-code-404 thumbnails google-drive-api

在我的应用程序中,当我使用GTLDriveFile的thumbnailLink下载文件的缩略图时,它会因服务器上找不到错误而失败(代码404)。以下是Google云端硬盘iOS SDK提供的文件thumbnailLink网址示例:

https://lh5.googleusercontent.com/eR-ahfZKPGcrqzhfh8Y4_tr7nwpdIdbkPxo19tjBeVPh0gE-QKSdT4fJrg8ajNhQ6g=s220

另外,我注意到,对于MS Word,MS Excel和MS Powerpoint文件,URL最常失败;虽然它们适用于PDF,png文件和各种其他文件类型。

还有其他人看到同样的问题吗?你是怎么解决的?

1 个答案:

答案 0 :(得分:0)

GTLServiceDrive *服务......

尝试

NSURL * url = [ NSURL URLWithString:thumbnailLink ];
NSMutableURLRequest * request = [ NSMutableURLRequest requestWithURL:url ];
[ service.authorizer authorizeRequest:request completionHandler:^(NSError *error)
     {
         NSURLSession * defaultSession = [ NSURLSession sessionWithConfiguration:[ NSURLSessionConfiguration defaultSessionConfiguration ]
                                                                        delegate:nil
                                                                   delegateQueue:[ NSOperationQueue mainQueue ] ];
         NSURLSessionDataTask * dataTask = [ defaultSession dataTaskWithRequest:request
                                                              completionHandler:^(NSData * data, NSURLResponse * response, NSError * error)
                                            {
                                                NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *)response;
                                                if ([ httpResponse isKindOfClass:[ NSHTTPURLResponse class ] ] && httpResponse.statusCode == 200 && data)
                                                {
                                                    UIImage * image = [ UIImage imageWithData:data ];

                                                    ...
                                                }
                                            } ];
         [ dataTask resume ];
     } ];

示例:

logShow