Facebook对话框,注销和访问令牌(Facebook iOS SDK) [英] Facebook dialog, logout and access token (Facebook iOS SDK)

查看:232
本文介绍了Facebook对话框,注销和访问令牌(Facebook iOS SDK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When a Facebook dialog is created with code like this

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

是否可以使用会话?

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

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


推荐答案

我创建了Facebook对象viewDidLoad

I create the Facebook object in viewDidLoad

_facebook = [[Facebook alloc] init];

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

I have a tableView. When the user clicks on an entry, an action sheet pops up with 3 choices

1发送电子邮件

2在Facebook上分享

2 share on Facebook

3从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. I use

[_facebook logout:self]; 

而且方法

- (void)fbDidLogout is called.

当用户点击在Facebook上分享时,此代码将运行

When the user clicks on "share on Facebook", this code is run

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中,我也尝试过使用

In viewDidLoad, I've also tried to use

_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:

putting in fbDidLogin:

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

但永远不会调用fbDidLogin。

but fbDidLogin is never called.

编辑

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

I resolved using the FB october api (while I've not found a solution with the november one).

这篇关于Facebook对话框,注销和访问令牌(Facebook iOS SDK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆