无法使用Facebook Object API创建非标准对象属性

时间:2013-04-25 17:08:52

标签: opengraph facebook-opengraph facebook-ios-sdk

我正在尝试使用Facebook Object API创建Facebook对象,然后列出它们。 Based on the documentation我们应该能够在'data'字段中存储非标准对象属性,例如,食物对象的卡路里值或山对象的高程高度。

但是当我尝试创建对象时,我无法在对象浏览器,图形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];
                                   }
                               }];

创建一个对象(方法2):

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​​”的数据字段。

这是图api资源管理器的响应示例:

    {
      "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";
            }
        );
    },...

数据字段在哪里?

1 个答案:

答案 0 :(得分:1)

哇。我只想出了自己。 您的自定义属性需要在Facebook应用设置页面中预定义。

  1. 转到developers.facebook.com/apps/your app
  2. 在左侧,选择Open Graph - &gt;类型 - &gt;选择你感兴趣的对象类型,
  3. 您将看到对象属性列表。那里有一个神奇的“添加属性”按钮!
  4. 添加“自定义”属性后,对象API现在可以正确创建具有该属性的新对象。