[英]Facebook dialog, logout and access token (Facebook iOS SDK)
When a Facebook dialog is created with code like this 使用这样的代码创建Facebook对话框时
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: apiKey, @"api_key", nil];
[facebook dialog:@"stream.publish" andParams:params andDelegate:self];
is there the possibility to use sessions? 是否有可能使用会话?
I succeeded in publishing a post on a user's post wall, but how allow the user to logout? 我成功地在用户的帖子墙上发布帖子,但是如何允许用户注销? Moreover I obtain this error when I try to access to current user information.
此外,当我尝试访问当前用户信息时,我收到此错误。
{
error = {
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
I create the Facebook object in viewDidLoad 我在viewDidLoad中创建了Facebook对象
_facebook = [[Facebook alloc] init];
I have a tableView. 我有一个tableView。 When the user clicks on an entry, an action sheet pops up with 3 choices
当用户单击某个条目时,会弹出一个包含3个选项的操作表
1 send an email 1发送电子邮件
2 share on Facebook 2在Facebook上分享
3 log out from Facebook: it should be there only if the user is logged, however for the moment it's there and it works. 3从Facebook注销:它应该只在用户登录时存在,但是目前它在那里并且它有效。 I use
我用
[_facebook logout:self];
and moreover the method 而且这个方法
- (void)fbDidLogout is called.
When the user clicks on "share on Facebook", this code is run 当用户点击“在Facebook上分享”时,将运行此代码
SBJSON *jsonWriter = [SBJSON new];
NSDictionary *actionLinks = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@"Some text", @"text",
@"http://try.com",@"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"is using...", @"name",
@"It's an app….", @"caption",
@"Download!", @"description",
@"http://ituneslink", @"href",
nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
API_KEY, @"api_key",
@"Message", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",nil];
[_facebook dialog:@"stream.publish" andParams:params andDelegate:self];
[jsonWriter release];
In viewDidLoad, I've also tried to use 在viewDidLoad中,我也尝试过使用
_facebook.accessToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"AccessToken"];
_facebook.expirationDate = (NSDate *) [[NSUserDefaults standardUserDefaults] objectForKey:@"ExpirationDate"];
_permissions = [[NSArray arrayWithObjects: @"read_stream", @"offline_access",nil] retain];
if ([_facebook isSessionValid] == NO) {
[_facebook authorize:API_KEY permissions:_permissions delegate:self];
}
putting in fbDidLogin: 放入fbDidLogin:
[[NSUserDefaults standardUserDefaults] setObject:_facebook.accessToken forKey:@"AccessToken"];
[[NSUserDefaults standardUserDefaults] setObject:_facebook.expirationDate forKey:@"ExpirationDate"];
but fbDidLogin is never called. 但永远不会调用fbDidLogin。
EDIT 编辑
I resolved using the FB october api (while I've not found a solution with the november one). 我解决了使用FB october api(虽然我没有找到11月的解决方案)。
看起来这是一个权限问题,请尝试:
[facebook setPermission:@"offline_access"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.