我是使用Open Graph的新手,并且没有看到Facebook教程或文档说明如何执行此操作。这是在Xcode 6的iOS 8上完成的。
我希望我的判决能够说出
I just got a score of *350*! Can you beat it?
但不知道如何将我的self.score
添加到开放图表故事中!
我没有要显示的代码,因为Facebook的教程已经过时了。如果有人能够为我提供更好的代码,使用自定义Open Graph(或更好的解决方案)来发布上述行,那么我将非常感激。
答案 0 :(得分:0)
因为Facebook代码错了,我会解释我是如何找到方法的,然后发布完整的代码。
我忘记了开放图形的想法,并决定发布一个由按钮触发的简单条件字符串。从那里我使用了来自here的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);
}
}
}
}];
}