views:

251

answers:

3

Hello- I am working on an app which will upload videos to a Facebook users wall, however I have not had much success. I present an extended permissions dialog window, and then use the face.video.upload method call. In the debugger, it seems like each parameter is set correctly, however the ext permission dialog never completely displays, and the video file never uploads.

The video file is stored in the app's documents directory (record and playback work fine) but the upload is broken. I have the video.upload parameters in the dialogDidSucceed: method, and I have modified the FBRequest.m generatePostBody: method to accept video files.

Any help would be tremendous, as I have been banging my head against the wall on this one. Thanks in advance.

Here is the view controller code:

-(IBAction)loginToFacebook

{ session = [[FBSession sessionForApplication:kAPIKey secret:kAPISecret delegate:self] retain];

FBLoginDialog *loginDialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];

[loginDialog show];

}

-(IBAction)askPermission { //---------------ask permission---------------------/ FBPermissionDialog *permDialog = [[[FBPermissionDialog alloc]init]autorelease];

permDialog.delegate = self;

permDialog.permission = @"video_upload";

[permDialog show];

}

-(void)dialogDidSucceed:(FBPermissionDialog *)dialog {

//---------------video file path--------------------/
NSString *path = [NSString stringWithFormat:@"%@/Documents/%@.mov", NSHomeDirectory(), aSelectedQuote.quoteID];

//---------------video data converter---------------/

NSData *videoData = [NSData dataWithContentsOfFile:path];

videoFileName = [NSString stringWithUTF8String:[videoData bytes]];

//---------------dict for FB upload-----------------/
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];

[args setObject:videoFileName forKey:@"video"];
[args setObject:aSelectedQuote.quoteTitle forKey:@"title"];

//---------------FBRequest--------------------------/
FBRequest *uploadVideoRequest = [FBRequest requestWithDelegate:self];

[uploadVideoRequest call:@"facebook.video.upload" params:args dataParam:videoData];

//[uploadVideoRequest call:@"facebook.video.upload" params:args];


NSLog(@"Upload video button pushed.");

}

-(void)dialogDidCancel:(FBDialog *)dialog { NSLog(@"user canceled request"); }

-(void)session:(FBSession *)session didLogin:(FBUID)uid { NSLog(@"user with id %lld logged in.",uid);

NSString *fql = [NSString stringWithFormat:@"select uid, name from user where uid == %lld", session.uid];

NSDictionary *params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];

[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];

}

/* -(void)sessionDidLogout:(FBSession *)session { } */

-(void)request:(FBRequest *)request didLoad:(id)result { if ([result isKindOfClass:[NSArray class]]) { NSArray *users = result; NSDictionary *user = [users objectAtIndex:0]; NSString *name = [user objectForKey:@"name"];

         NSLog(@"FBRequest didLoad: - logged in as %@",name);
     }

}

-(void)dialog:(FBDialog *)dialog didFailWithError:(NSError *)error { NSLog(@"Error (%d) %@", [error code], [error localizedDescription]); }

Here is the FBRequest.m code:

- (NSMutableData*)generatePostBody {

NSMutableData* body = [NSMutableData data]; NSString* endLine = [NSString stringWithFormat:@"\r\n--%@\r\n", kStringBoundary];

[self utfAppendBody:body data:[NSString stringWithFormat:@"--%@\r\n", kStringBoundary]];

for (id key in [_params keyEnumerator]) { [self utfAppendBody:body data:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key]]; [self utfAppendBody:body data:[_params valueForKey:key]]; [self utfAppendBody:body data:endLine]; }

if (_dataParam != nil) { if ([_dataParam isKindOfClass:[UIImage class]]) { NSData* imageData = UIImagePNGRepresentation((UIImage*)_dataParam); [self utfAppendBody:body data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"photo\"\r\n"]]; [self utfAppendBody:body data:[NSString stringWithString:@"Content-Type: image/png\r\n\r\n"]]; [body appendData:imageData]; } else { NSAssert([_dataParam isKindOfClass:[NSData class]], @"dataParam must be a UIImage or NSData"); /*
[self utfAppendBody:body data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"data\"\r\n"]]; [self utfAppendBody:body data:[NSString stringWithString:@"Content-Type: content/unknown\r\n\r\n"]]; [body appendData:(NSData*)_dataParam]; */ if ([_method isEqualToString:@"facebook.video.upload"]) { [self utfAppendBody:body data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"data.mov\"\r\n"]]; [self utfAppendBody:body data:[NSString stringWithString:@"Content-Type: video/quicktime\r\n\r\n"]]; } else { [self utfAppendBody:body data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"data\"\r\n"]]; [self utfAppendBody:body data:[NSString stringWithString:@"Content-Type: content/unknown\r\n\r\n"]]; }

}
[self utfAppendBody:body data:endLine];

}

FBLOG2(@"Sending %s", [body bytes]); return body; }

A: 

You're setting videoFileName to the raw bytes of the videofile:

videoFileName = [NSString stringWithUTF8String:[videoData bytes]];
....
[args setObject:videoFileName forKey:@"video"];

I think you meant:

videoFileName = [path lastPathComponent];

I hope this fixes your problem.

tonklon
Thanks, tonclon.I actually removed this line completely, and I was able to get this working with a few other code additions. I will post the complete code a little later this week. I appreciate your help!
SliceofPy
A: 

Hey SliceofPy,

I'm facing similar issues. if you could post your complete code it would be very helpful and appreciated.

Thanks, NormalPPL

eytan
Can you give me an idea of your specific error?
SliceofPy
A: 

HI

I am also trying to upload a video to my facebook account but I am gettting "request Timed out Error"

Please help me out of this

SivaTeja