如何自定义Open Graph故事



我是Open Graph的新手,在Facebook教程或文档中看不到如何做到这一点。这是在iOS 8的Xcode 6中完成的。

我想让我的句子说

I just got a score of *350*! Can you beat it?

但不知道如何将我的self.score添加到开放图故事中!

我没有代码可以显示,因为Facebook的教程已经过时了。如果有人能为我提供更好的代码,让我在发布上面的行时不会出现自定义开放图错误(或更好的解决方案),我将不胜感激。

因为Facebook的代码是错误的,我将解释我是如何找到方法的,然后发布完整的代码。

我忘记了开放图的想法,决定只发布一个由按钮触发的简单条件字符串。从那里开始,我使用了Facebook的代码,只使用回退,因为上面的"共享对话框"无法完全工作。

从那里我刚用了[NSString stringWithFormat:%@%@%@,string1,self.score,string2];

以下是示例代码(修改为其他代码的通用代码):

-(IBAction)facebookShare:(id)sender {
//Set Variables
int scoreText
int highScoreText
//Format the description
NSString *description;
NSString *t1 = @"I just got a score of ";
NSString *t1Alt = @"I just got a new high score of ";
NSString *t2 = @"! Can you beat it?";
if (self.newHigh == NO){
    description = [NSString stringWithFormat:@"%@%@%@",t1,scoreText,t2];
} else if (self.newHigh == YES){
    description = [NSString stringWithFormat:@"%@%@%@",t1Alt,highScoreText,t2];
}
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Edit Me", @"name",
                               @"Edit Me", @"caption",
                               description, @"description",
                               @"http://Edit.Me.Too/", @"link",
                               @"http://And.Me.Too/", @"picture",
                               nil];
/* * * * * * * * * * * DO NOT EDIT BELOW THIS LINE * * * * * * * * * * * *
 *                                                                       *
 *                                                                       *
 *               From here on, this shows share screen                   *                         
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                              if (error) {
                                                  // An error occurred, we need to handle the error
                                                  // See: https://developers.facebook.com/docs/ios/errors
                                                  NSLog(@"Error publishing story: %@", error.description);
                                              } else {
                                                  if (result == FBWebDialogResultDialogNotCompleted) {
                                                      // User cancelled.
                                                      NSLog(@"User cancelled.");
                                                  } else {
                                                      // Handle the publish feed callback
                                                      NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
                                                      if (![urlParams valueForKey:@"post_id"]) {
                                                          // User cancelled.
                                                          NSLog(@"User cancelled.");
                                                      } else {
                                                          // User clicked the Share button
                                                          NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                          NSLog(@"result %@", result);
                                                      }
                                                  }
                                              }
                                          }];

}

最新更新