iOS - Facebook Open Graph Api - 确保用户生成照片

时间:2013-07-09 01:50:51

标签: ios facebook facebook-graph-api ios6

我试图实现以下目标: enter image description here

这需要打开图形请求看起来像这样: (https://developers.facebook.com/docs/opengraph/howtos/adding-photos-to-stories/

POST /me/cookbook:eat?
  recipe=http://www.example.com/recipes/pizza/&
  image[0][url]=http://www.example.com/recipes/pizza/pizza.jpg&
  image[0][user_generated]=true&
  image[1][url]=http://www.example.com/recipes/pizza/pizza2.jpg&
  image[1][user_generated]=true&
  access_token=VALID_ACCESS_TOKEN

然而,使用此代码:(来自这里的简明教程: https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/) 我不知道如何将用户生成的标志设置为true。因此,照片看起来很小。

- (void)postOpenGraphActionWithPhotoURL:(NSString*)photoURL
{
    // First create the Open Graph meal object for the meal we ate.
    id<SCOGMeal> mealObject = [self mealObjectForMeal:self.selectedMeal];

    // Now create an Open Graph eat action with the meal, our location, 
    // and the people we were with.
    id<SCOGEatMealAction> action = 
        (id<SCOGEatMealAction>)[FBGraphObject graphObject];
    action.meal = mealObject;
    if (self.selectedPlace) {
        action.place = self.selectedPlace;
    }
    if (self.selectedFriends.count > 0) {
        action.tags = self.selectedFriends;
    }
    if (photoURL) {
        NSMutableDictionary *image = [[NSMutableDictionary alloc] init];
        [image setObject:photoURL forKey:@"url"];

        NSMutableArray *images = [[NSMutableArray alloc] init];
        [images addObject:image];

        action.image = images;
    }

    // Create the request and post the action to the 
    // "me/<YOUR_APP_NAMESPACE>:eat" path.
    [FBRequestConnection startForPostWithGraphPath:@"me/<YOUR_APP_NAMESPACE>:eat"
                             graphObject:action
                       completionHandler:
     ^(FBRequestConnection *connection, id result, NSError *error) {
         NSString *alertText;
         if (!error) {
             alertText = [NSString stringWithFormat:
                             @"Posted Open Graph action, id: %@",
                             [result objectForKey:@"id"]];
         } else {
             alertText = [NSString stringWithFormat:
                             @"error: domain = %@, code = %d",
                             error.domain, error.code];
         }
         [[[UIAlertView alloc] initWithTitle:@"Result" 
                                     message:alertText 
                                    delegate:nil 
                           cancelButtonTitle:@"Thanks!" 
                           otherButtonTitles:nil] 
          show]; 
     }
     ];
}

这里,mealobject符合FBGraphObject协议。使用我继承的相同协议,如何将用户生成的标志设置为true?该文档没有提到任何“user_generated”。

或者我应该不使用协议并根据所需的帖子参数手动格式化字符串?

编辑: 我尝试使用字符串而不是FBOpenGraph对象手动执行此操作,并且我成功地复制了相同的功能。

但是,我无法显示多张照片或将其设置为用户生成。

SCProtocols.h:

#import <Foundation/Foundation.h>
#import <FacebookSDK/FacebookSDK.h>

@protocol SCOGMeal<FBGraphObject>

@property (retain, nonatomic) NSString *id;
@property (retain, nonatomic) NSString *url;

@end


@protocol SCOGEatMealAction<FBOpenGraphAction>

@property (retain, nonatomic) id<SCOGMeal> meal;

@end

1 个答案:

答案 0 :(得分:2)

您应该可以替换代码:

if (photoURL) {
    NSMutableDictionary *image = [[NSMutableDictionary alloc] init];
    [image setObject:photoURL forKey:@"url"];

    NSMutableArray *images = [[NSMutableArray alloc] init];
    [images addObject:image];

    action.image = images;
}

使用:

if (photoURL) {
    NSMutableDictionary *image = [[NSMutableDictionary alloc] init];
    [image setObject:photoURL forKey:@"url"];

    [image setObject:@"true" forKey:@"user_generated"]; // <======= ***add this line***

    NSMutableArray *images = [[NSMutableArray alloc] init];
    [images addObject:image];

    action.image = images;
}