upload Video to Facebook using iOS6 Social Framework

前端 未结 2 907
耶瑟儿~
耶瑟儿~ 2020-12-29 16:55

I want to publish a video file to facebook. Previously I used the Facebook iOS SDK3.0 and it works. However, for iOS6 Social Framework, there is problem.

 _         


        
相关标签:
2条回答
  • 2020-12-29 17:24

    I'm working the same issue. I think your error is from ARC and NSData *videoData gets deleted before the return from performRequestWithHandler.

    0 讨论(0)
  • 2020-12-29 17:25

    Here is my research: First, the video data cannot be part of the parameter list, since it will render the SLRequest invalid and that is the crash you are experiencing.

    The video data must go in the multi part section of the request.

    Now,there is a need to associate the parameters with the multipart data and that is the tricky part. So it is necessary to use the source attribute to make that link.

    Source requires a URL in a string format set it in the parameters and set the same value in the filename field in the multipart request.

    That should do it.

    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]];
    
    0 讨论(0)
提交回复
热议问题