在 Facebook、Twitter 和电子邮件上捕获视频共享
Posted
技术标签:
【中文标题】在 Facebook、Twitter 和电子邮件上捕获视频共享【英文标题】:captured video sharing on facebook, twitter and email 【发布时间】:2013-10-22 04:34:41 【问题描述】:我想拍摄一段视频,然后在一些社交网站和电子邮件上分享,所以我已经拍摄了视频并将其保存到相册中,现在我不知道如何分享拍摄/保存的视频,请提出建议为此,这是我用于捕获视频存储的代码..:-
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
// NSLog(@"dictionary info %@", info);
if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath))
// Copy it to the camera roll.
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath);
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
vidPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"];
[vidPath retain];
BOOL success = [videoData writeToFile:vidPath atomically:NO];
NSLog(@"Written file on path success? , %@\n", (success ? @"YES" : @"NO"));
[picker dismissModalViewControllerAnimated:YES];
更新
我已尝试使用此代码生成用于共享视频的小 url,但它不起作用:(
NSString *apiEndpoint = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@",vidPath];
[apiEndpoint retain];
shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
encoding:NSASCIIStringEncoding
error:nil];
[shortURL retain];
在这里,我可以将视频存储在照片库和文档目录中,现在我想分享它,那该怎么做?请帮忙!
【问题讨论】:
【参考方案1】:对于 Facebook,正如 Luis 在 their answer here 中所建议的那样:
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
NSURL *videoPathURL = [[NSURL alloc]initFileURLWithPath:videoPath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:videoPath];
NSString *status = @"One step closer.";
NSDictionary *params = @@"title":status, @"description":status;
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:url
parameters:params];
[request addMultipartData:videoData
withName:@"source"
type:@"video/quicktime"
filename:[videoPathURL absoluteString]];
电子邮件
-(IBAction)sendmailPress:(id)sender
MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
if (Apicker != nil)
[Apicker setSubject:@""];
[Apicker setMessageBody:@" " ishtml:NO];
[Apicker setToRecipients:toRecipients];
Apicker.mailComposeDelegate = self;
NSData *mym=[NSData dataWithContentsOfFile:VideoPath];
NSLog(@"%@",mym);
[Apicker addAttachmentData:mym mimeType:@".Extension" fileName:videoname];
[self presentModalViewController:Apicker animated:YES];
[Apicker release];
【讨论】:
这对您有帮助吗? 实际上我需要一个适用于所有人的全球解决方案,因为我也想在 fb、twitter 和电子邮件上分享我捕获的视频...... @D-eptdeveloper,请参阅我的更新答案。抱歉,我不知道 Twitter。 +1 感谢您的努力:)我会为 fb 和电子邮件尝试此代码。 嘿哥们,如果你能告诉我如何使用这个fb请求?这将是一个很大的帮助以上是关于在 Facebook、Twitter 和电子邮件上捕获视频共享的主要内容,如果未能解决你的问题,请参考以下文章
无法将 Facebook 和 Twitter 添加到 UIActivityViewController
Facebook、Twitter 和电子邮件无法使用 ShareKit
Facebook、Twitter 等。登录网站未获取电子邮件
Javascript - WinRT - 如何与 twitter 或 Facebook 分享分数?
如何在 ios 的 UIactivity 视图控制器中仅显示 facebook、twitter 和电子邮件(目标 c)?