使用 graph api 在 Facebook 上发布高分

发布于 2024-09-26 06:26:24 字数 2064 浏览 2 评论 0原文

编辑:10-10-9
我认为当 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 与动态数据集成,它不会显示在 Facebook 帖子附件部分。

 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 告诉我 Components 是一个未声明的变量,

[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];

Edit: 10-9-10
I think the app is crashing when the JSON library tries to parse the

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

How would i format it so that JSON can parse it?

Here's the JSON code line

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

Can anyone point me to a tutorial on how to do this? I can easily post the static text in the code block below but i can't integrate an NSString with dynamic data, it doesn't show up on the Fb post attachment section.

 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];

Update:
the problem is the string i'm using is from a time interval of the difference of 2 weeks and the out put is [components week] and then xcode tells me components is an undeclared variable

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

here's the whole date code block that i get the string above from:

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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离不开的别离 2024-10-03 06:26:24

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

Try stringWithFormat [NSString stringWithFormat:@"%@", highscore]; instead of highscore

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文