大佬教程收集整理的这篇文章主要介绍了通过iOS App在Twitter上分享视频,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以使用相同的方式共享图像
SLrequest *postrequest = [SLrequest requestForserviCEType:SLserviCETypeTwitter requestMethod:SLrequestMethodPOST URL:requestuRL parameters:message]; if (isImagE) { NSData *data = UIImagePNGRepresentation(imgSELEcted); [postrequest addMultipartData:data withName:@"media" type:@"image/png" filename:@"TestImage.png"]; } postrequest.account = account; [postrequest performrequestWithHandler:^(NSData *responseData,NShttpURLResponse *urlResponse,NSError *error) { if (!error) { NSLog(@"Upload Sucess !"); } }];
它的工作原理如下:
>请求1:发送具有视频大小(以字节为单位)的init请求.这将返回我们必须在请求2和3中使用的媒体ID号.
>请求2:使用请求1中返回的媒体ID号上传视频数据.
>请求3:视频上传完成后,将“FINALIZE”请求发送回Twitter API.这让Twitter API知道视频文件的所有块都已完成上传.
注意Twitter API接受“块”中的视频上传.因此,如果您的视频文件很大,您可能希望将其拆分为多个文件,因此您必须多次重复“请求2”(不要忘记每次都增加“segment_index”数字).
我已经开始编写以下代码了.尝试一下并尝试一下.我稍后会更新我的答案以改进它.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // Assign the mediatype to a String NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; // check the media type String so we can determine if its a video if ([mediaType isEqualToString:@"public.movie"]) { NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; NSData *webData = [NSData dataWithContentsOfURL:videoURL]; // Get the size of the file in bytes. NSString *yourPath = [NSString StringWithFormat:@"%",videoURL]; NSFileManager *man = [NSFileManager defaultManager]; NSDictionary *attrs = [man attributesOfItemAtPath:yourPath error: NULL]; UInt32 result = [attrs fileSize]; //[self tweetVideoStage1:webData :result]; [self tweetVideo:webData :result :1 :@"n/a"]; } } -(void)tweetVideo:(NSData *)videoData :(int)videoSize :(int)R_770_11845@ode :(NSString *)mediaId { NSURL *twitterVideo = [NSURL URLWithString:@"https://upload.twitter.com/1.1/media/upload.json"]; // Set the parameters for the first twitter video request. NSDictionary *postDict; if (mode == 1) { postDict = @{@"command": @"INIT",@"@R_349_10586@l_bytes" : videoSize,@"media_type" : @"video/mp4"}; } else if (mode == 2) { postDict = @{@"command": @"APPEND",@"media_id" : mediaId,@"segment_index" : @"0",@"media" : videoData }; } else if (mode == 3) { postDict = @{@"command": @"FINALIZE",@"media_id" : mediaId }; } SLrequest *postrequest = [SLrequest requestForserviCEType:SLserviCETypeTwitter requestMethod:SLrequestMethodPOST URL:requestuRL:twitterVideo parameters:postDict]; // Set the account and begin the request. postrequest.account = account; [postrequest performrequestWithHandler:^(NSData *responseData,NSError *error) { if (!error) { if (mode == 1) { // Parse the returned data for the JSON String // which contains the media upload ID. NSMutableDictionary *returnedData = [NSJSONserialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error] NSString *tweetID = [NSString StringWithFormat:@"%@",[returnedData valueForKey:@"media_id_String"]]; [self tweetVideo:videoData :result :2 :tweetID]; } else if (mode == 2) { [self tweetVideo:videoData :result :3 :mediaId]; } } else { NSLog(@"Error stage %d - %",mode,error); } }]; }
更新 – Twitter API错误 – https://dev.twitter.com/overview/api/response-codes
以上是大佬教程为你收集整理的通过iOS App在Twitter上分享视频全部内容,希望文章能够帮你解决通过iOS App在Twitter上分享视频所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。