【问题标题】:posting high score on facebook using graph api使用graph api在facebook上发布高分
【发布时间】:2011-04-21 02:40:31
【问题描述】:

编辑: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];

【问题讨论】:

    标签: ios facebook facebook-graph-api


    【解决方案1】:

    尝试使用 stringWithFormat [NSString stringWithFormat:@"%@", highscore]; 代替高分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多