我正在尝试将使用我的 iphone 应用程序拍摄的视频上传到 Facebook。
在我的应用程序的 .plist 中,我添加了
FacebookAppId、FacebookDisplayName、URLSchemes 和我已经向 Facebook 开发者注册了我的应用程序。
在 iPhone 设置中,我的应用程序被允许使用 Facebook 帐户
然后我允许我的用户为视频命名并给出描述,然后通过点击按钮将其上传到 Facebook。
- (void)buttonRequestClickHandler:(id)sender {
if (FBSession.activeSession.isOpen) {
//this is the path to the video
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];
//these are the title and description of the video
NSString *titleString = self.videotitle.text;
NSString *descripString = self.descrp.text;
NSDictionary *videoObject = @{
@"title":titleString,
@"description": descripString,
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
parameters:videoObject
HTTPMethod:@"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"Done: %@", result);
else
NSLog(@"Error: %@", error.localizedDescription);}];
}
这是我得到错误操作无法完成的地方。(com.facebook.sdk 错误 2。)所以显然我没有从 appDelegate 获得会话,也没有在这里登录。
else {
permissions = [NSMutableArray arrayWithObjects:@"publish_actions",@"publish_streams",nil];
[FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert THIS IS THE ERROR I GET
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// if otherwise we check to see if the session is open, an alternative to
// to the FB_ISSESSIONOPENWITHSTATE helper-macro would be to check the isOpen
// property of the session object; the macros are useful, however, for more
// detailed state checking for FBSession objects
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// send our requests if we successfully logged in
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
NSString *titleString = self.videotitle.text;
NSString *descripString = self.descrp.text;
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];
NSDictionary *videoObject = @{
@"title":titleString,
@"description": descripString,
[pathURL absoluteString]: videoData};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
parameters:videoObject
HTTPMethod:@"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"Done: %@", result);
else
NSLog(@"Error: %@", error.localizedDescription);}];
}}];
}}
谁能看到我在登录会话时做错了什么?
我将非常感谢任何人对此的帮助。