【发布时间】:2014-05-07 09:38:04
【问题描述】:
我对 Objective-c 非常陌生。基本上,我现在看到的都是黑色的。我被指派为我们正在制作的应用程序的 facebook 共享部分编写代码,相信我,我已经尝试了几乎所有的教程(没有一个有效,我已经尝试过)并在堆栈中解决了这里的问题,我仍然无法上传。所以请有人帮忙吗?
如何通过应用程序将视频上传到 Facebook?如果有,请提供示例代码。
这是我现在正在尝试的代码:
-(void)post
{
NSURL *videourl = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Here's to the Crazy Ones" ofType:@"mp4"];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSLog(@"PATH: %@", filePath);
NSDictionary *params = @{
@"title": @"uploading",
@"description": @"testing..."
};
NSLog(@"uploading...");
SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:videourl
parameters:params];
[uploadRequest addMultipartData:videoData
withName:@"source"
type:@"video/quicktime"
filename:[pathURL absoluteString]];
NSLog(@"Here it goes...");
uploadRequest.account = self.facebookAccount;
NSLog(@"Past uploadrequest...");
[FBSession setActiveSession:FBSession.activeSession];
[uploadRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// [FBSession setActiveSession:FBSession.activeSession];
if (!FBSession.activeSession.isOpen) {
// [FBSession openActiveSessionWithAllowLoginUI: YES];
[FBSession setActiveSession:FBSession.activeSession];
}
NSLog(@"response string: %@", responseString);
NSLog(@"Here I am...");
if(error){
NSLog(@"Error %@", error.localizedDescription);
}else
NSLog(@"%@", responseString);
}];
}
这样我得到一个错误:
{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
【问题讨论】:
-
我更新了帖子。谢谢。
标签: ios objective-c facebook ios7