如何使用SOCIAL KIT Framework从我的iOS应用程序上传视频到Facebook?

时间:2015-01-22 06:17:16

标签: ios objective-c facebook social

我已经在FBConnect

的帮助下完成了这项任务

但我想用iOS提供的框架来做,即Social.framework

我已经提到this reference了, 但它给我错误:

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

如果您对此有任何参考或任何新方法,请帮助我。

谢谢&的问候,

詹尼弗

2 个答案:

答案 0 :(得分:1)

最后,我可以使用SOCIAL框架在Facebook上发布视频。

以下是它的方式:

1)确保用户已登录FaceBook帐户。

然后,

-(IBAction)sharewithFacebook:(id)sender{


    __block ACAccount * facebookAccount;
    ACAccountStore* accountStore = [[ACAccountStore alloc] init];

    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];


    NSArray *accounts = [accountStore
                         accountsWithAccountType:facebookAccountType];
    facebookAccount = [accounts lastObject];



    NSURL *videourl = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"YourVideoName" ofType:@"mp4"];
    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
    NSData *videoData = [NSData dataWithContentsOfFile:filePath];

    NSDictionary *params = @{
                             @"title": @"Uploaded from my app",
                             @"description": @"https://github.com/Vishaliphone"
                             };

    SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                  requestMethod:SLRequestMethodPOST
                                                            URL:videourl
                                                     parameters:params];


    [uploadRequest addMultipartData:videoData
                           withName:@"source"
                               type:@"video/quicktime"
                           filename:[pathURL absoluteString]];

    uploadRequest.account = facebookAccount;

    [uploadRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];


        if(error){
            NSLog(@"Error %@", error.localizedDescription);
        }else
            NSLog(@"%@", responseString);
    }];


}

希望它能帮助他人。

感谢。

答案 1 :(得分:0)

您需要将访问令牌设置为能够获取数据或代表用户执行操作。请确保您的访问令牌处于活动状态。