【发布时间】:2013-06-05 17:09:25
【问题描述】:
好的。我有一个按钮(如下),我从应用程序中获取一些信息并将其发布到用户的 FB 提要。
它几乎从来没有第一次工作。他们,在那之后它通常会很好地工作。发生的情况是,当我按下按钮时,它告诉我我已经授予应用程序使用 FB 的权限(我只想第一次看到,而不是每次都看到)。然后,当我从那里按 OK 时,它会返回应用程序,或者会显示我可以实际发布到墙上的页面(这是我想要的)。
我正在尝试不同的方法以使其更一致地工作。这里有什么东西会导致这种行为吗?
-(IBAction)fbButton:(id)sender {
if (![facebook isSessionValid]) {
[facebook authorize:permissions];
[permissions release];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
//Post to Wall
NSString *poopDollas = [[NSString alloc] initWithFormat:
@"sometext $%@!",dollas.text];
SBJSON *jsonWriter = [[SBJSON new] autorelease];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
@"Get Started",@"name",@"http://www.facebook.com/pages/xx/204640386498567",@"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
// Dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"DM", @"name",
poopDollas, @"caption",
@"sometext", @"description",
@"http://www.facebook.com/pages/xx/204640386498567", @"link",
@"http://farm8.staticflickr.com/7185/6999841878_e66a8e00fc_t.jpg", @"picture",
actionLinksStr, @"actions",
nil];
FBDialog *delegate = (FBDialog *)[UIApplication sharedApplication].delegate;
[facebook dialog:@"feed" andParams:params andDelegate:(id <FBDialogDelegate>)delegate];
}
【问题讨论】:
-
几个 cmets: 1) 请升级您的 SBJson 副本。您正在使用的课程在多年前被分成了两个;许多,许多个重要的错误已经被修复。 2) 请升级您的代码以使用 ARC。 3)请使用字典静态初始化器以提高可读性(
@{ @"key": @"value" })。
标签: iphone ios nsuserdefaults facebook-ios-sdk sbjson