示例Facebook目标代码。 [英] Example Facebook object code.

查看:111
本文介绍了示例Facebook目标代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从Facebook获取使用自定义对象的示例代码。我创建了一个自定义的动作来利用Facebook的故事。

Facebook文档:

https:/ /developers.facebook.com/docs/opengraph/overview/

This is the sample code i get from Facebook for the using custom objects. I created this with a custom action to make use of the Facebook story.
Facebook Documentation:
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时崩溃。

Im curious how can i use this object for an action in the Facebook IOS sdk. I have tried to use the following codes and it crash upon creating the 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中。
,它仍然崩溃。

[edit]
I have created FBOpenGraphObject and use FBRequestConnection method startForPostOpenGraphObject: completionHandler. Within the completion handler, i retrieve the id from the result and put it in another FBOpenGraphObject with the id. and it still crash.

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'终止app
,原因:
' - [__ NSCFBoolean dataUsingEncoding:]:无法识别的选择器发送到
instance 0x3a118530'

2013-08-16 18:47:11.013 ZombieBlackout[3408:907] -[__NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3a118530 2013-08-16 18:47:11.015 ZombieBlackout[3408:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3a118530'


推荐答案

我在API调用之前添加了这些行,并且工作正常!

I just added these lines before API call and that works fine!

    object[@"create_object"] = @"1";
    object[@"fbsdk:create_object"] = @"1";

似乎这是Facebook SDK中的错误!它尝试编码布尔值

It seems this is a bug in Facebook SDK! it tries to encode Boolean value

示例代码应该是这样的

    NSMutableDictionary<FBGraphObject> *object =
        [FBGraphObject openGraphObjectForPostWithType:@"{YOUR NAMESPACE}:{YOUR OBJECT TYPE}"
                                                title:@"title"
                                                image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
                                                  url:@"http://samples.ogp.me/192059197639963"
                                          description:@"description"];

    object[@"create_object"] = @"1";
    object[@"fbsdk:create_object"] = @"1";

    [FBRequestConnection startForPostWithGraphPath:@"me/objects/{YOUR NAMESPACE}:{YOUR OBJECT TYPE}"
                                       graphObject:object
                                 completionHandler:^(FBRequestConnection *connection,
                                                     id result,
                                                     NSError *error) {
                                     NSLog(@"%@",result);
                                 }];
}

这篇关于示例Facebook目标代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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