使用iOS SDK将大型视频上传到Facebook

时间:2013-07-29 15:15:17

标签: ios facebook facebook-graph-api video

如何在iOS Facebook SDK中上传大型视频?我有一个4分钟的视频,总是出错并且出现未知错误。

1 个答案:

答案 0 :(得分:1)

我必须为视频参数构建我的NSData,如下所示:

videoData = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedAlways error:&error];

我还必须在FBRequestConnection.m中更改此方法,并开始工作:

//
// Generates a URL for a batch containing only a single request,
// and names all attachments that need to go in the body of the
// request.
//
// The URL contains all parameters that are not body attachments,
// including the session key if present.
//
// Attachments are named and referenced by name in the URL.
//
- (NSString *)urlStringForSingleRequest:(FBRequest *)request forBatch:(BOOL)forBatch
{
    [request.parameters setValue:@"json" forKey:@"format"];
    [request.parameters setValue:kSDK forKey:@"sdk"];
    NSString *token = request.session.accessTokenData.accessToken;
    if (token) {
        [request.parameters setValue:token forKey:kAccessTokenKey];
        [self registerTokenToOmitFromLog:token];
    }

    NSString *baseURL;
    if (request.restMethod) {
        if (forBatch) {
            baseURL = [kBatchRestMethodBaseURL stringByAppendingString:request.restMethod];
        } else {
            baseURL = [kRestBaseURL stringByAppendingString:request.restMethod];
        }
    } else {
        if (forBatch) {
            baseURL = request.graphPath;
        } else {
            NSString *const kVideoGraphBaseURL = @"https://graph-video." FB_BASE_URL @"/";
            if (([request.HTTPMethod isEqualToString:@"PUT"] || [request.HTTPMethod isEqualToString:@"POST"]) && [request.graphPath rangeOfString:@"videos"].location != NSNotFound)
            {
                baseURL = [kVideoGraphBaseURL stringByAppendingString:request.graphPath];
            }
            else
            {
                baseURL = [kGraphBaseURL stringByAppendingString:request.graphPath];
            }
        }
    }

    NSString *url = [FBRequest serializeURL:baseURL
                                     params:request.parameters
                                 httpMethod:request.HTTPMethod];
    return url;
}

iOS SDK中的视频支持似乎很差。