我正在尝试使用 Facebook 对象 API 创建 Facebook 对象,然后列出它们。 根据文档,我们应该能够在“数据”字段中存储非标准对象属性,例如,食物对象的卡路里值,或山对象的海拔高度。
但是当我尝试创建对象时,我在对象浏览器、图形 api 浏览器或对象列表的响应中都看不到“数据”字段。
它是一个错误吗?
我如何创建对象(方法 1):
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[@"type"] = @"mangasendalpha:Template";
object[@"title"] = @"another one!";
object[@"image"] = @"http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Enchiladas_suizas.jpg/800px-Enchiladas_suizas.jpg";
object[@"url"] = @"https://url.com";
NSDictionary *data = @{@"keyword":@"haha"};
object[@"data"] = data;
[FBRequestConnection startForPostOpenGraphObject:object
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"Success %@", result);
[self tryList];
}
}];
创建一个对象(方法二):
NSString *type = @"mangasendalpha:Template";
NSString *title = @"hei hei can you see the data?";
NSString *imageUri = @"http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Enchiladas_suizas.jpg/800px-Enchiladas_suizas.jpg";
NSString *url = @"http://www.url.com";
NSString *description = @"a new template description";
NSDictionary *objectProperties = @{@"keyword":@"hehe"};
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
FBRequest *request = [FBRequest requestForPostOpenGraphObjectWithType:type title:title image:imageUri url:url description:description objectProperties:objectProperties];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(error)
{
LogError(@"%@",error);
}
else
{
Log(@"success:%@", result);
[self tryList];
}
}];
[connection start];
无论我如何创建对象,我都可以正确看到标题、图像等,除了应该显示“keywords = haha”的数据字段。
这是来自 graph api explorer 的响应示例:
{
"id": "106170429585804",
"url": "http://www.url.com/",
"type": "mangasendalpha:template",
"title": "hei hei can you see the data?",
"image": [
{
"url": "http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Enchiladas_suizas.jpg/800px-Enchiladas_suizas.jpg"
}
],
"description": "a new template description",
"updated_time": "2013-04-25T16:55:48+0000",
"created_time": "2013-01-09T05:51:44+0000",
"application": {
"id": "512497238785794",
"name": "MangaSendAlpha",
"url": "https://www.facebook.com/apps/application.php?id=512497238785794"
},
"is_scraped": false,
"post_action_id": 524865977555471
}
如果我尝试列出对象,明确说我想要 id、image 和 DATA:
- (void) tryList
{
NSString *path = [NSString stringWithFormat:@"/me/objects/mangasendalpha:Template?fields=id,image,data"];
NSDictionary *parameters = nil;
FBRequest *request = [FBRequest requestWithGraphPath:path parameters:parameters HTTPMethod:@"GET"];
[request startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphObject> *response,
NSError *error)
{
if (!error)
{
Log(@"response: %@", response);
}
else
{
Log(@"has error: %@", error);
}
}];
}
这就是我将得到的:
data = (
{
id = 106170429585804;
image = (
{
url = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Enchiladas_suizas.jpg/800px-Enchiladas_suizas.jpg";
}
);
},
{
id = 386877688092664;
image = (
{
url = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Enchiladas_suizas.jpg/800px-Enchiladas_suizas.jpg";
}
);
},...
数据字段在哪里?