I'm trying to download file from Google Drive using the SDK provided for iOS. But it is giving me this error:
Error Domain=com.google.HTTPStatus Code=400 "(null)"
Here is the download code:
GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];
NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media",
file.identifier];
GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
// Do something with data
} else {
NSLog(#"An error occurred: %#", error);
}
}];
However I'm able to list all the files and I double checked the bundle identifier as well.
Any suggestion what I'm missing?
Add key (API keys for iOS) param in URL
then try like following code:
GTLDriveFile *file;//Your Object
NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?key=YOUR_KEY_iOS",
file.identifier];
GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url]; //GTLServiceDrive *service;
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
// File Download here
} else {
NSLog(#"An error occurred: %#", error);
}
}];
I've tried Successfuly, but not use following code.NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media",
file.identifier];
I use file.webContentLink.
Related
I am trying to download from google drive file in iOS and getting error in the following
GTLServiceDrive* googleDriveService = [[GTLServiceDrive alloc] init];
NSString *urlTest = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media",itemIdentifier[indexPath.row]];
GTMSessionFetcher *fetcherTest = [googleDriveService.fetcherService fetcherWithURLString:urlTest];
[fetcherTest beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
NSLog(#"File size is : %.2f MB",(float)data.length/1024.0f/1024.0f);
// Do something with data
} else {
NSLog(#"error: %#", [error localizedDescription]);
}
}];
error: The operation couldn’t be completed. (com.google.HTTPStatus
error 403.)
I'm trying to download video from youtube but getting error.
Error mention in code
my code
-(void)downloadVideo{
LBYouTubeExtractor *extractor = [[LBYouTubeExtractor alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:(#"https://www.youtube.com/watch?v=%#"), videoIdToDownload ]] quality:LBYouTubeVideoQualityLarge];
[extractor extractVideoURLWithCompletionBlock:^(NSURL *videoURL, NSError *error) {
if(!error) {
NSLog(#"Did extract video URL using completion block: %#", videoURL);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSError* error = nil;
NSData* data1 = [NSData dataWithContentsOfURL:videoURL options:NSDataReadingUncached error:&error]; //data1 is nill
if (error) { //Error Domain=NSCocoaErrorDomain Code=256 "The file “3gpp;+codecs="mp4v.20.3,+mp4a.40.2"&fallback_host=tc.v8.cache4.googlevideo.com&itag=36” couldn’t be opened."
NSLog(#"error=%#", error);
}else{
NSString *filename = [NSString stringWithFormat:(#"video_%#.mp4"), videoIdToDownload ];
[data1 writeToFile:[dirPath stringByAppendingPathComponent:filename] atomically:YES];
NSLog(#"File %# successfully saved", filename);
}
});
} else {
NSLog(#"Failed extracting video URL using block due to error:%#", error);
}
}];
}
using this lib
https://github.com/larcus94/LBYouTubeView
If anyone now solution please help me.
Thanks
This is what I am doing to fetch files from Googledrive, but I am getting GTLDriveFile's downloadUrl nil. I tried for "exportLinks" also, but that is again nil. Please suggest.
#pragma mark- Downloading GDrive Files
-(void)downloadGDriveFiles:(GTLDriveFile *)file{
GTMHTTPFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:file.downloadUrl];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
{
if (error == nil)
{
NSLog(#"Retrieved file content");
}
else
{
[self showAlert:#"" message:#"Unable to download this file"];
}
}];
}
Thanks !!
I am working with an iOS application in which I have to upload images on Box Service. After authentication process when I uploaded images from the NSBundle, it uploaded successfully.
when I uploaded from a path image get uploaded but only file is created, no data is uploaded.
Below is my uploaded method:
-m(void)uploadimages:(UIImage*)image
{
BoxFileBlock fileBlock = ^(BoxFile *file)
{
[self fetchFolderItemsWithFolderID:self.folderID name:self.navigationController.title];
dispatch_sync(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"File Upload Successful" message:[NSString stringWithFormat:#"File has id: %#", file.modelID] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
});
};
BoxAPIJSONFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
{
BOXLog(#"status code: %li", (long)response.statusCode);
BOXLog(#"upload response JSON: %#", JSONDictionary);
};
BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
NSInteger randomNumber = arc4random() % 100;
NSString *filename = [NSString stringWithFormat:#"PicBackMan-%ld.jpg",(long)randomNumber];
builder.name = filename;
builder.parentID = self.folderID;
NSLog(#"builder.parentID : %#",builder.parentID);
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
path = [[pathList objectAtIndex:0] stringByAppendingPathComponent:#"image.jpg"];
NSLog(#"Path o/p is %#",path);
NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath: path];
NSLog(#"inputStream DIRECT : %#",inputStream);
NSError *error;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
if (!error) {
if (fileAttributes != nil) {
NSLog(#"File attributes found.");
} else {
NSLog(#"File attributes not found.");
}
} else {
NSLog(#"%#", [error localizedDescription]);
long long contentLength = [[fileAttributes objectForKey:NSFileSize] longLongValue];
NSLog(#"fileAttributes : %#",fileAttributes);
NSLog(#"contentLength : %lld",contentLength);
[[BoxSDK sharedSDK].filesManager uploadFileWithInputStream:inputStream contentLength:contentLength MIMEType:nil requestBuilder:builder success:fileBlock failure:failureBlock progress:nil];
}
I am getting the output, but my file is not uploaded with data, only an image of file with name created.
I am getting following output in log:
builder.parentID : 2323165189
2014-08-19 17:25:58.431 BoxSDKSampleApp[17252:1243051] /Users/bettermac9/Library/Application Support/iPhone Simulator/7.1-64/Applications/30DFB367-599B-4F39-AD62-D27B1081FE99/Documents/image.jpg
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] inputStream DIRECT : <__NSCFInputStream: 0x7f8f7ae5db00>
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] The operation couldn’t be completed. (Cocoa error 260.)
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] fileAttributes : (null)
2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] contentLength : 0
Please help me out, as per my knowledge I think I am doing any mistake in reading the file from path and sending to NSinputstream. Please help me out.
Thank you
I'm a newbie in objective-c and I really need your help. I've been trying to solve this for hours now. And I still can't find a solution. Here is my codes:
-(void)post
{
[self connectWithFacebook];
NSLog(#"session: %hhd", FBSession.activeSession.isOpen);
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Here's to the Crazy Ones" ofType:#"mp4"];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *videoObject = #{
#"title": #"FB SDK 3.1",
#"description": #"hello there !",
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:#"me/videos"
parameters:videoObject
HTTPMethod:#"POST"];
NSLog(#"here i am");
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"after upload request");
if (!error)
NSLog(#"Done: %#", result);
else
NSLog(#"Error: %#", error.localizedDescription);
}];
}
AND
- (void) connectWithFacebook {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate openSessionWithAllowLoginUI:YES];
}
And here's from the AppDelegate
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
NSArray *permissions = #[#"publish_stream"];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (error) {
NSLog (#"Handle error %#", error.localizedDescription);
} else {
NSLog(#"No error");
}
}];
}
Here's from the console:
2014-05-08 15:02:49.385 camera[3748:60b] Error: The operation couldn’t be completed. (com.facebook.sdk error 5.)
Your help will be greatly appreciated. Thank you. I really have no idea what to do next.
one possible error for com.facebook.sdk error 5 is
"This status update is identical to the last one you posted. Try
posting something different, or delete your previous update."