我在努力(失败了很多!)使用Facebook iOS sdk。我想在不离开应用程序的情况下发布一个关于用户运行的故事。我正在尝试使用Facebook内置的对象"course“和内置的action来跑步。
我发现文档非常混乱,我的代码已经变得非常纠结,我确信这是尝试实现这个解决方案的最糟糕的方式。
我在下面的代码中得到的错误是:
2014-04-01 23:10:13.238 Fitness_App[2313:60b] Encountered an error posting to Open Graph: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x16ba5190 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 1611072;
message = "The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: course.";
type = Exception;
};
};
code = 500;},com.facebook.sdk:ErrorSessionKey=}
我一直在为这个问题而苦苦挣扎,却找不到解决方案!
-(void) publishStory
{
// instantiate a Facebook Open Graph object
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
// specify that this Open Graph object will be posted to Facebook
object.provisionedForPost = YES;
// for og:title
object[@"title"] = @"running title";
// for og:type, this corresponds to the Namespace you've set for your app and the object type name
object[@"type"] = @"fitness.course";
// for og:description
object[@"description"] = @"running description";
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
// get the object ID for the Open Graph object that is now stored in the Object API
NSString *objectId = [result objectForKey:@"id"];
NSLog([NSString stringWithFormat:@"object id: %@", objectId]);
// Further code to post the OG story goes here
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:@"fitness.course"];
[FBRequestConnection startForPostWithGraphPath:@"/me/fitness.runs" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog([NSString stringWithFormat:@"OG story posted, story id: %@", [result objectForKey:@"id"]]);
} else {
// An error occurred, we need to handle the error
NSLog(@"Encountered an error posting to Open Graph: %@", error.description);
}
}];
} else {
// An error occurred
NSLog(@"Error posting the Open Graph object to the Object API: %@", error);
}
}];
}发布于 2014-04-26 12:48:59
有两个地方出了问题。
object[@"type"] = @"fitness.course";type应等于@"namespace:object"。
[action setObject:objectId forKey:@"fitness.course"];关键字是您的对象名称。
再次检查您的代码,玩得开心^-^
发布于 2014-08-14 20:36:27
尝试将这句话替换为"action setObject:objectId forKey:@"fitness.course";“
使用这一条
"action setObject:objectId forKey:@"course";“
https://stackoverflow.com/questions/22798048
复制相似问题