How to define a “GeoPoint” property in Facebook SDK for iOS

蓝咒 提交于 2019-12-02 15:08:27

问题


I'm trying to geo-tag an Open Graph story by creating an Open Graph object that inherits from the predefined "place" object. However, I can't figure out how to define the GeoPoint property "place:location" in iOS! There is an answer to a similar question here: https://stackoverflow.com/a/19386730/824515 which I have tried without success.

Now, I'm trying to break down the problem by setting up a "place" object directly, but it doesn't help. I get this error message:

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;
    };

This is my test code:

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];

I have tried to replace the line object[@"location"] = … with everything I can think of, such as:

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";

The error message was identical for all the versions A - E.


回答1:


I believe they need to be nested dictionaries, so you need to create a "place" graph object, and then set that as the place on your open graph object. Something like:

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;



回答2:


This worked for me:

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]);
  } 
}];



回答3:


Try this:

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

Facebook doc doesn't mention it clearly that we should put the additional property under the key data.



来源:https://stackoverflow.com/questions/20376634/how-to-define-a-geopoint-property-in-facebook-sdk-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!