这是我从 Facebook 获得的使用自定义对象的示例代码。我使用自定义操作创建了这个以利用 Facebook 故事。
Facebook 文档:
https ://developers.facebook.com/docs/opengraph/overview/
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:@"sotd_facebook:new_zombie"
title:@"Sample New Zombie"
image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:@"http://samples.ogp.me/191078581053171"
description:@""];;
[FBRequestConnection startForPostWithGraphPath:@"me/objects/sotd_facebook:new_zombie"
graphObject:object
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
}];
我很好奇如何在 Facebook IOS sdk 中使用这个对象进行操作。我尝试使用以下代码,但它在创建 FBRequestConnection 时崩溃。
[__NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3af00530
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3af00530'
[编辑]
我创建了 FBOpenGraphObject 并使用 FBRequestConnection 方法 startForPostOpenGraphObject: completionHandler。在完成处理程序中,我从结果中检索 id 并将其放入具有 id 的另一个 FBOpenGraphObject 中。它仍然崩溃。
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject
openGraphObjectForPostWithType:@"sotd_facebook:new_zombie"
title:@"Sample New Zombie"
image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:@"http://samples.ogp.me/191078581053171"
description:@""];
[FBRequestConnection startForPostOpenGraphObject:object
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
// handle the result
if (error)
{
NSLog(@"Error sharing story: %@", error.localizedDescription);
}
else if(result != nil)
{
NSLog(@"Result: %@", result);
NSString* resultID = [result objectForKey:@"id"];
NSMutableDictionary<FBOpenGraphObject> *newObject = [FBGraphObject openGraphObjectForPost];
newObject.id = resultID;
[FBRequestConnection startForPostWithGraphPath:@"me/objects/sotd_facebook:new_zombie"
graphObject:newObject completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
// handle the result
if (error)
{
NSLog(@"Error sharing story: %@", error.localizedDescription);
}
else
{
NSLog(@"Result: %@", result);
}
}];
}
}];
崩溃日志:
2013-08-16 18:47:11.013 ZombieBlackout[3408:907]-[__NSCFBoolean dataUsingEncoding:]:无法识别的选择器发送到实例 0x3a118530 2013-08-16 18:47:11.015 ZombieBlackout[3408:907] *终止应用程序未捕获的异常“NSInvalidArgumentException”,原因:“-[__NSCFBoolean dataUsingEncoding:]:无法识别的选择器发送到实例 0x3a118530”