尝试使用FBConnect for iPhone将视频上传到Facebook

编程入门 行业动态 更新时间:2024-10-07 15:20:15
本文介绍了尝试使用FBConnect for iPhone将视频上传到Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个将视频上传到Facebook用户墙的应用程序,但是我没有太大的成功。我提出一个扩展权限对话窗口,然后使用face.video.upload方法调用。在调试器中,似乎每个参数设置正确,但是ext权限对话框从未完全显示,视频文件从不上传。

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.

视频文件存储在该应用程序的文档目录(记录和播放工作正常),但上传已损坏。我在dialogDidSucceed:方法中有video.upload参数,我修改了FBRequest.m generatePostBody:方法来接受视频文件。

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.

这是视图控制器代码:

-(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代码:

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

推荐答案

您正在将videoFileName设置为视频文件的原始字节:

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

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

我想你的意思是:

videoFileName = [path lastPathComponent];

我希望这能解决您的问题。

I hope this fixes your problem.

更多推荐

尝试使用FBConnect for iPhone将视频上传到Facebook

本文发布于:2023-11-26 18:49:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634758.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   FBConnect   iPhone   Facebook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!