我正在使用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视图
答案 0 :(得分:0)
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");
}
}];
答案 1 :(得分:0)
我为此目的编写了一个框架:
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);
}
}];