如何定义“GeoPoint” Facebook SDK for iOS中的属性 [英] How to define a "GeoPoint" property in Facebook SDK for iOS
问题描述
我正在尝试通过创建一个继承自预定义place对象的Open Graph对象来对Open Graph故事进行地理标记。但是,我无法弄清楚如何在iOS中定义GeoPoint属性place:location!这里有一个类似问题的答案:我有 https://stackoverflow.com/a/19386730/824515 尝试没有成功。
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;
};
这是我的测试代码:
答:
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];
我试图替换行对象[@location] = ...
包含我能想到的一切,例如:
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";
所有版本A-E的错误消息都相同。
The error message was identical for all the versions A - E.
推荐答案
这对我有用:
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]);
}
}];
这篇关于如何定义“GeoPoint” Facebook SDK for iOS中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!