我正在制作一个将视频上传到Facebook用户墙上的应用,但是我没有取得多大成功。我提出了一个扩展权限对话框窗口,然后使用face.video.upload方法调用。在调试器中,似乎每个参数都设置正确,但是ext权限对话框永远不会完全显示,并且视频文件永远不会上传。
视频文件存储在应用程序的文档目录中(记录和播放工作正常)但上传已损坏。我在dialogDidSucceed:方法中有video.upload参数,我修改了FBRequest.m generatePostBody:方法来接受视频文件。
任何帮助都是巨大的,因为我一直在撞墙上的头。 提前谢谢。
以下是视图控制器代码:
-(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]);
}
这是FBRequest.m代码:
- (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;
}
答案 0 :(得分:0)
您正在将视频FileName设置为视频文件的原始字节:
videoFileName = [NSString stringWithUTF8String:[videoData bytes]];
....
[args setObject:videoFileName forKey:@"video"];
我认为你的意思是:
videoFileName = [path lastPathComponent];
我希望这可以解决您的问题。