iOS - Facebook Open Graph Api - 确保照片是用户生成的 [英] iOS - Facebook Open Graph Api -- ensuring that photos are user generated

查看:100
本文介绍了iOS - Facebook Open Graph Api - 确保照片是用户生成的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现以下功能:

I am attempting to achieve the following:

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

This necessitates the open graph request to look something like this: (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://开发人员。 facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/
我不知道如何将用户生成的标记设置为true。因此,照片看起来很小。

However, using this code: (from the scruptious tutorial here: https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/ ) I do not know how to set the user generated flag to true. Because of this, the photo appears small.

- (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。

here, mealobject conforms to the FBGraphObject protocol. Using the same protocol that I am inheriting from, how do I set the user generated flag to be true? The documentation makes no mention of anything "user_generated".

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

Or should I not use the protocol and manually format the string as per the desired post parameters?

编辑:
我试图手动使用字符串而不是FBOpenGraph对象,我成功地复制了相同的功能。

I tried to manually do this using a string instead of the FBOpenGraph object, and I succeeded in replicating this same functionality.

但是,我一直无法以获得多张照片出现或将其设置为用户生成。

However, I have been unable to get multiple photos to appear or set them to be user generated.

SCProtocols.h:

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


推荐答案

你应该可以替换你的代码:

You should be able to replace your code:

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

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

    action.image = images;
}

with:

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

这篇关于iOS - Facebook Open Graph Api - 确保照片是用户生成的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆