我试图向Facebook分享一个“故事”,其中包含一个名为share的动作,以及一个名为“picture_location”的对象。 “picture_location”具有名为“location”的自定义GeoPoint属性。
我想要的是能够在用户的墙上展示一个类似于:
的故事UserName 使用 AppName 分享图片的位置。
问题不在于故事的格式,而是显示地图附件。
地图附件还应显示一个标记,以显示在“位置”地理点中传递的坐标。
我试图解决这个问题3个小时甚至没有成功。
到目前为止,这就是我所拥有的:
NSMutableDictionary<FBGraphObject> *openGraphObject =
[FBGraphObject openGraphObjectForPostWithType:@"*namespace*:picture_location"
title:@"Some Title"
image:nil
url:nil
description:nil];
openGraphObject[ @"location" ] = @{ @"latitude": self.imageLatitude, @"longitude": self.imageLongitude }; // imageLatitude and imageLongitude are NSNumbers
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
// Link the object to the action
[action setObject:openGraphObject forKey:@"picture_location"];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = @"*namespace*:share";
// If the Facebook app is installed and we can present the share dialog
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params])
{
// Show the share dialog
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:@"*namespace*:share"
previewPropertyName:@"picture_location"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// There was an error
NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
} else {
// Success
NSLog(@"result %@", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
} else {
// FALLBACK GOES HERE
}
但结果是Facebook应用程序打开了,带有正确的故事文本和标题,但是图像为空白而没有地图。
编辑:这些是类似的问题,其解决方案我已经尝试过但无济于事。
答案 0 :(得分:0)
解决这个问题的正确方法是参数的发送方式。至少我无法为iOS找到任何官方文档。
如果您的对象具有geopoint属性,则Facebook会自动为您标记地点:
openGraphObject [@&#34; data&#34;] = @ {@&#34; location&#34;:@ {@&#34;纬度&#34;: self.imageLatitude,@&#34;经度&#34;:self.imageLongitude}};
示例代码:
NSLog(@"Sharing: Facebook Location Share");
NSMutableDictionary<FBGraphObject> *openGraphObject =
[FBGraphObject openGraphObjectForPostWithType:@"*namespace*:location"
title:@"Location to share"
image:mapImage // This is the one that will be shown on the preview share dialogue
url:@"An URL to link to"
description:@"A description"];
// THIS is the key, the custom properties MUST be within a dictionary called "data"
openGraphObject[@"data"] = @{@"location": @{@"latitude": self.imageLatitude, @"longitude": self.imageLongitude }};
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
// Link the object to the action
[action setObject:openGraphObject forKey:@"location"];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = @"*namespace*:put";
// If the Facebook app is installed and we can present the share dialog
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params])
{
// Show the share dialog
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:@"*namespace*:put"
previewPropertyName:@"location"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// There was an error
NSLog(@"%@",[NSString stringWithFormat:@"Error publishing story: %@", error.description]);
} else {
// Success
NSLog(@"result %@", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
}
else
{
// Could present an alert or use the Feed Dialogue instead
}