我正在尝试实现以下目标:
这需要打开图请求看起来像这样:
(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];
}
];
}
这里,meatobject符合FBGraphObject协议。使用与我继承的协议相同的方法,如何将用户生成的标志设置为true?该文档没有提及任何“user_generation”。
还是不应该使用协议并根据所需的发布参数手动设置字符串格式?
编辑:
我尝试使用字符串而不是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
最佳答案
您应该可以替换代码:
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;
}