使用图形api在facebook上发布高分

时间:2010-10-05 03:19:56

标签: ios facebook facebook-graph-api

编辑:10-9-10
我认为当JSON库试图解析

时,应用程序崩溃了
[NSString stringWithFormat:@"%d weeks",[components week]];  

我如何格式化它以便JSON可以解析它?

这是JSON代码行

NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
        NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                              kAppId, @"api_key",
                               @"Share on Facebook",  @"user_message_prompt",
                               actionLinksStr, @"action_links",
                              attachmentStr, @"attachment",
                               nil];

有人能指点我如何做到这一点的教程吗?我可以轻松地在下面的代码块中发布静态文本,但我无法将NSString与动态数据集成,它不会显示在Fb帖子附件部分。

 NSDictionary *attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                        @"Testing", @"name",
                         @"testing2", @"caption",
                          [NSString stringWithFormat:@"%d weeks",[components week]], @"description"//Xcode says components undeclared 

//highscore, @"description", //here's the problem, highscore is the NSString variable.
                          @"http://testing.com/", @"href", nil];

更新: 问题是我正在使用的字符串来自2周差异的时间间隔,输出为[components week]然后xcode告诉我组件是未声明的变量

[NSString stringWithFormat:@"%d weeks",[components week]]

这是我从上面得到字符串的整个日期代码块:

NSString *dateStr = @"20100716";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *startDate = [dateFormat dateFromString:dateStr]; 
NSDate *endDate = [NSDate date];

NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];

NSUInteger unitFlags = NSWeekCalendarUnit | NSDayCalendarUnit;

NSDateComponents *components = [gregorian components:unitFlags
fromDate:startDate
toDate:endDate options:0];

NSInteger weeks = [components week];
NSInteger days = [components day];

1 个答案:

答案 0 :(得分:0)

尝试使用stringWithFormat [NSString stringWithFormat:@"%@", highscore];而不是高分