我试图使用stories向Facebook发布一个带有动作的开放图谱对象,但我总是收到一个没有任何细节的错误。我将我正在使用的所有代码总结成一个单独的方法,供大家参考:
- (void)publishToGraph {
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[@"title"] = @"Example title";
object[@"type"] = @"rs-coupcash";
object[@"description"] = @"Example description";
object[@"url"] = @"http://exampleurl.com/idk";
object[@"image"] = @[@{@"url": @"http://exampleurl.com/example_url.png", @"user_generated" : @"true" }];
[FBSession openActiveSessionWithPublishPermissions:@[@"email", @"public_profile", @"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (!error && state == FBSessionStateOpen) {
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSString *objectId = [result objectForKey:@"id"];
NSLog(@"Object ID: %@", objectId);
id<FBOpenGraphAction> actionObject = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[actionObject setObject:objectId forKey:@"coupon"];
[FBRequestConnection startForPostWithGraphPath:@"/me/rs-coupcash:favorite" graphObject:actionObject completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[[FBSession activeSession] close];
if(!error) {
NSLog(@"OG story posted, story ID: %@", [result objectForKey:@"id"]);
} else {
NSLog(@"Error: %@", error);
}
}];
} else {
NSLog(@"Error: %@", error);
}
}];
} else {
NSLog(@"Error: %@", error);
}
}];
}
我收到的错误信息:
错误域=com.facebook.sdk 代码=5 "操作无法完成。(com.facebook.sdk error 5.)" 用户信息=0x114544670 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ErrorSessionKey=, 过期日期: 2014-08-26 05:18:45 +0000, 刷新日期: 2014-06-27 16:56:32 +0000, 尝试刷新日期: 0001-12-30 00:00:00 +0000, **权限**:( 已安装, "公共资料", 邮箱, "发布动态" )>, com.facebook.sdk:ParsedJSONResponseKey={ body = { error = { code = 1; message = "发生未知错误。"; type = OAuthException; }; }; code = 500; }}