iPhone Facebook Video Upload

前端 未结 5 1428
[愿得一人]
[愿得一人] 2020-12-01 03:35

I\'ve been working on this for a couple of days now and just can\'t seem to find a straight answer or example anywhere. I am trying to upload a video to facebook from within

相关标签:
5条回答
  • 2020-12-01 03:42

    I’ve got a video upload branch in my fork of the Facebook SDK on GitHub. I did not touch it for several weeks, but it used to work fine (only it requires the old-style authentication, see this branch). There are some comments in the FBVideoUpload class header, but the interface is pretty much self-explanatory. There’s also some helpful discussion under my pull request – especially the thing about SSL certificates on the api-video cluster that could make the whole issue easier, but I did not review the code yet.

    [Rant: It’s a pity that the Facebook SDK for iOS does not exactly thrive on GitHub. There are many pull requests, but the official developers never seem to merge anything, not even trivial typo fixes in the documentation. Most of the time the pull requests simply sit there until rejected.]

    And yes, did I mention that the video upload code is a messy hack? The video upload code is a messy hack. It parses some auth tokens and it could break anytime soon, but it was the only way I could make it work back then.


    Update: The video upload branch is no more, you can now easily upload video using the official SDK:

    NSData *videoData = [NSData dataWithContentsOfURL:movieURL];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
        …, @"title", 
        …, @"description", 
        …, @"file",
        videoData, @"clip.mov",
        nil];
    [facebook requestWithGraphPath:@"me/videos" andParams:params andHttpMethod:@"POST" andDelegate:self];
    

    This is “the right way to do it”™, the previous solution was just a temporary hack.

    0 讨论(0)
  • 2020-12-01 03:46

    Actually all, it's worth mentioning to keep an eye out on Facebook's various engineering blogs. This one is dated from October 2011, so doesn't have the "current" SDK: http://developers.facebook.com/blog/post/532/

    But the sample still works if you modify the bundle ID, add the URL scheme to the plist, and add your own App ID to the view controller:

    enter image description here

    This is the most useful information i've found on video uploading - I don't know why Facebook obscure this away from their main SDK docs! It's bizarrely not linked anywhere, i had to do some digging around...

    0 讨论(0)
  • 2020-12-01 03:47

    You can use new graph api to upload video :

    • Use me/videos as graph path
    • Add user_videos permission to your app
    • Set filename to match your file's extension in the POST request (after Content-Disposition:)

    You can use this fork https://github.com/johnmph/facebook-ios-sdk and have a param dictionary like that :

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:movieData, @"source", @"File.mov", @"filename", nil];
    [m_facebook requestWithGraphPath:@"me/videos" andParams:params andHttpMethod:@"POST" andDelegate:self];
    

    I added also to this fork a method to track the upload status (by example to use with a progress bar)

    0 讨论(0)
  • 2020-12-01 03:53
    - (void)viewDidLoad
    {
        facebook = [[Facebook alloc] initWithAppId:@"276907032339239"];
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    - (IBAction)buttonClicked:(id)sender
    {
        NSArray* permissions = [[NSArray alloc] initWithObjects:
                                @"publish_stream", nil];
        [facebook authorize:permissions delegate:self];
        [permissions release];
    }
    - (void)fbDidLogin
    {
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"mov"];
        NSData *videoData = [NSData dataWithContentsOfFile:filePath];
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       videoData, @"video.mov",
                                       @"video/quicktime", @"contentType",
                                       @"Video Test Title", @"title",
                                       @"Video Test Description", @"description",
                                       nil];
        [facebook requestWithGraphPath:@"me/videos"
                             andParams:params
                         andHttpMethod:@"POST"
                           andDelegate:self];
        NSLog(@"hiiiiiiiii");
    
    }
    
    -(void)fbDidNotLogin:(BOOL)cancelled 
    {
    
        NSLog(@"did not login");
    
    }
    
    - (void)request:(FBRequest *)request didLoad:(id)result
    {
        if ([result isKindOfClass:[NSArray class]])
        {
            result = [result objectAtIndex:0];
        }
        NSLog(@"Result of API call: %@", result);
    }
    
    - (void)request:(FBRequest *)request didFailWithError:(NSError *)error
    {
        NSLog(@"Failed with error: %@", [error localizedDescription]);
    }
    
    0 讨论(0)
  • 2020-12-01 04:05

    Did you try sending it to an email as facebook sugested in http://www.facebook.com/help/?faq=12345 You could use the email subject to set the caption of the video.

    0 讨论(0)
提交回复
热议问题