复制Facebook的股票代码时,“在程序中意外”

时间:2014-10-09 19:41:21

标签: ios objective-c facebook

我已经从Facebook的开发者网站复制了代码,将Facebook共享集成到我的应用程序中:

NSMutableDictionary<FBGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:@whatsyourinneragefb:inner_age
                                        title:@Sample Inner Age
                                        image:@https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png
                                          url:@http://samples.ogp.me/578838518886846
                                  description:@];;

[FBRequestConnection startForPostWithGraphPath:@"me/objects/whatsyourinneragefb:inner_age"
                                   graphObject:object
                             completionHandler:^(FBRequestConnection *connection,
                                                 id result,
                                                 NSError *error) {
                                 // handle the result
                             }];  

但是,@whatsyourinneragefb之前的“@”会产生错误"Unexpected @ in program。此外,诸如@https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png之类的行具有白色的@https:,其余的突出显示为绿色,就好像它是注释一样,所以即使上面的错误消失,我觉得这也行不通。所以:

如何解决第一个错误?

代码是否有效,还是需要调整才能工作?

所有帮助表示赞赏。

2 个答案:

答案 0 :(得分:3)

Objective-C中的字符串文字看起来像@"this"

例如,将@Sample Inner Age更改为@"Sample Inner Age"

答案 1 :(得分:0)

我不确定你从哪里复制代码;我在Facebook开发者网站上找不到任何“内心时代”的提法。你有可能误解了编辑他们提供的来源的方式。使用注入数据的正确实现将为字符串文字提供引号(您也缺少描述):

NSMutableDictionary<FBGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:@"whatsyourinneragefb:inner_age"
                                    title:@"Sample Inner Age"
                                    image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
                                      url:@"http://samples.ogp.me/578838518886846"
                              description:@"<you're missing a description>"];

[FBRequestConnection startForPostWithGraphPath:@"me/objects/whatsyourinneragefb:inner_age"
                               graphObject:object
                         completionHandler:^(FBRequestConnection *connection,
                                             id result,
                                             NSError *error) {
                             // handle the result
                         }];