如何在Facebook SDK for iOS中定义“GeoPoint”属性

时间:2013-12-04 13:26:25

标签: ios facebook opengraph facebook-ios-sdk

我正在尝试通过创建一个继承自预定义“place”对象的Open Graph对象来对Open Graph故事进行地理标记。但是,我无法弄清楚如何在iOS中定义GeoPoint属性“place:location”!这里有一个类似问题的答案:https://stackoverflow.com/a/19386730/824515我试过没有成功。

现在,我试图通过直接设置“地方”对象来解决问题,但它没有帮助。我收到此错误消息:

error =         {
        code = 100;
        message = "(#100) Object Missing a Required Value: Object at URL '' of type 'place' is invalid because a required property 'place:location' of type 'geo_point' was not provided.";
        type = OAuthException;
    };

这是我的测试代码:

A:

FBRequestConnection *connection = [[[FBRequestConnection alloc] init] autorelease];
id<FBOpenGraphObject> object = [FBGraphObject openGraphObjectForPost];
object[@"type"] = @"place";
object[@"title"] = @"Test Title";

object[@"location"] = @{@"latitude": @"48.85831", @"longitude": @"2.29465"};

NSLog(@"object = %@", [object description]);
FBRequest *objectRequest = [FBRequest requestForPostOpenGraphObject: object];
[connection addRequest: objectRequest
     completionHandler: ^(FBRequestConnection *connection, id result, NSError *error) {
         DLine();
         if (error)
             NSLog(@"Error: %@", error);
         else
             NSLog(@"Result: %@", [result description]);
     }];
[connection start];

我尝试用我能想到的所有内容替换行object[@"location"] = …,例如:

B:

object[@"place:location"] = @{@"latitude": @"48.85831", @"longitude": @"2.29465"};

C:

object[@"place"] = @{@"location":
                         @{@"latitude": @"48.85831", @"longitude": @"2.29465"}
                     };

d

object[@"location:latitude"] = @"48.85831";
object[@"location:longitude"] = @"2.29465";

E:

object[@"place:location:latitude"] = @"48.85831";
object[@"place:location:longitude"] = @"2.29465";

所有版本A-E的错误消息都相同。

3 个答案:

答案 0 :(得分:1)

我认为它们需要是嵌套的词典,因此您需要创建一个“位置”图形对象,然后将其设置为打开的图形对象上的位置。类似的东西:

id<FBGraphObject> place = [FBGraphObject graphObject];
id<FBGraphObject> location = [FBGraphObject graphObject];
location[@"latitude"] = @"48.85831";
location[@"longitude"] = @"2.29465";
place[@"location"] = location;
place[@"name"] = @"foobar";

object[@"place"] = place;

答案 1 :(得分:1)

这对我有用:

NSMutableDictionary<FBOpenGraphObject> *store = [FBGraphObject openGraphObjectForPost];
store.provisionedForPost = YES;
store[@"og"] = @{ @"title":@"Test Title", @"type":@"place" };
store[@"place"] = @{ @"location" : @{ @"longitude": @"-58.381667", @"latitude":@"-34.603333"} };

[FBRequestConnection startForPostWithGraphPath:@"me/objects/place"
                                 graphObject:@{@"object":store}
                           completionHandler:^(FBRequestConnection *connection,
                                               id result,
                                               NSError *error) {
  if (!error) {
    NSLog(@"result: %@", result);
  }
  else {
    NSLog(@"%@", [NSString stringWithFormat:@"%@", error.description]);
  } 
}];

答案 2 :(得分:0)

试试这个:

object[@"data"][@"location"] = @{@"latitude": @"48.85831", @"longitude": @"2.29465"};

Facebook doc没有明确提到我们应该将附加属性放在密钥data下。