Facebook对话框,注销和访问令牌(Facebook iOS SDK)

时间:2010-11-17 20:13:45

标签: iphone ios facebook

使用此类代码创建Facebook对话框时

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: apiKey, @"api_key", nil];
[facebook dialog:@"stream.publish" andParams:params andDelegate:self];

是否可以使用会话?

我成功地在用户的帖子墙上发布帖子,但是如何允许用户注销? 此外,当我尝试访问当前用户信息时,我收到此错误。

{
    error = {
        message = "An active access token must be used to query information about the current user.";
        type = OAuthException;
    };
}

2 个答案:

答案 0 :(得分:3)

我在viewDidLoad

中创建了Facebook对象
_facebook = [[Facebook alloc] init];

我有一个tableView。当用户点击某个条目时,会弹出一个包含3个选项的操作表

1发送电子邮件

在Facebook上分享

3从Facebook注销:它应该只在用户登录时存在,但是目前它在那里并且它有效。 我用

[_facebook logout:self]; 

而且方法

- (void)fbDidLogout is called.

当用户点击“在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];

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

放入fbDidLogin:

[[NSUserDefaults standardUserDefaults] setObject:_facebook.accessToken forKey:@"AccessToken"];
 [[NSUserDefaults standardUserDefaults] setObject:_facebook.expirationDate forKey:@"ExpirationDate"];

但永远不会调用fbDidLogin。

修改

我解决了使用FB october api(虽然我没有找到11月的解决方案)。

答案 1 :(得分:0)

看起来这是权限问题,请尝试:

[facebook setPermission:@"offline_access"];