如何在 iOS 中将 Theta 360 度照片发布到 Facebook

Posted

技术标签:

【中文标题】如何在 iOS 中将 Theta 360 度照片发布到 Facebook【英文标题】:How to post the Theta 360 degree photo to facebook in ios 【发布时间】:2017-10-27 10:24:15 【问题描述】:

我正在使用 Theta Camera SDK 进行 360 度拍摄。

我想将这张照片发布到 Facebook,这是 360 度全景照片。

         UIImage *image = [UIImage imageNamed:@"IMG_0133.JPG"];


         NSString *token = [NSString stringWithFormat:@"%@", [FBSDKAccessToken currentAccessToken].tokenString];
         NSDictionary *param = @@"message": @"test",
                                 @"access_token": token,
                                  @"photo":image,
                                 @"allow_spherical_photo": [NSNumber numberWithBool:true]

                                 ;

         FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                       initWithGraphpath:@"me/photos"
                                       parameters:param
                                       HTTPMethod:@"post"];

         [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                               id result,
                                               NSError *error)
          

              if (!error)
              
                  NSLog(@"post success");

              
          ];

但它是像普通图片一样发布的,不是 360 度视图

【问题讨论】:

【参考方案1】:
     UIImage *image = [[UIImage alloc]initWithData:[[NSUserDefaults standardUserDefaults] objectForKey :@"image_NSdata]];
         NSData *imgData = UIImageJPEGRepresentation(image, 1);
         NSLog(@"Size of Image(bytes):%ld",(unsigned long)[imgData length]);

         float actualHeight = image.size.height;
         float actualWidth = image.size.width;



         NSDictionary * postDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"equirectangular", [NSNumber numberWithFloat:actualWidth] ,[NSNumber numberWithFloat:actualHeight], [NSNumber numberWithFloat:actualWidth] ,[NSNumber numberWithFloat:actualHeight], @"0",@"0", nil]
             forKeys:[NSArray arrayWithObjects:@"ProjectionType", @"CroppedAreaImageWidthPixels",@"CroppedAreaImageHeightPixels", @"FullPanoWidthPixels",@"FullPanoHeightPixels", @"CroppedAreaLeftPixels",@"CroppedAreaTopPixels", nil]];


         NSError * error = nil;

         NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:NSJSONWritingPrettyPrinted error:&error];
         NSString *resultAsString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
         NSLog(@"jsonData as string:\n%@ Error:%@", resultAsString,error);


         NSString *token = [NSString stringWithFormat:@"%@", [FBSDKAccessToken currentAccessToken].tokenString];
         NSDictionary *param = @
                                 

                                 @"access_token": token,
                                 @"photo":image,
                                 @"allow_spherical_photo": [NSNumber numberWithBool:true],
                                 @"spherical_metadata":resultAsString

                                 ;

         FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                       initWithGraphPath:@"me/photos"
                                       parameters:param
                                       HTTPMethod:@"post"];

         [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                               id result,
                                               NSError *error)
          

              if (!error)
              
                  NSLog(@"post success");

              
          ];

【讨论】:

【参考方案2】:

我为此目的编写了一个框架:

https://github.com/AppCoders-io/Facebook360

假设您已请求共享权限,这就是您要使用的:

[[Facebook360Manager sharedInstance] shareImage:[UIImage imageNamed:@"spherical360.jpg"]
                                      userCaption:@"Example caption..."
                                    horizontalFOV:360.0
                                  sharePreference:FacebookShareManagerPreferenceSphericalImage
                                  completionBlock:^(NSError * _Nullable error, NSString * _Nullable postID) 
                                    if (error) 
                                      NSLog(@"Error: %@",error);
                                    else
                                      NSLog(@"Shared successfully. Post ID: %@",postID);
                                    
                                  ];

【讨论】:

以上是关于如何在 iOS 中将 Theta 360 度照片发布到 Facebook的主要内容,如果未能解决你的问题,请参考以下文章

360度全景效果图,如何制作?

Android:使用 Android API 29 的 Ricoh Theta 连接问题

[JavaScript案例]360度全景照片

如何在微信中将多张图片一次性发送给指定联系人

如何在 iOS 中使用 VLC Player 使用 libvlc 播放 360 度视频

ios如何360度旋转控制