简体   繁体   中英

Facebook dialog, logout and access token (Facebook iOS SDK)

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

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

_facebook = [[Facebook alloc] init];

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

1 send an email

2 share on 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]; 

and moreover the method

- (void)fbDidLogout is called.

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

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

putting in fbDidLogin:

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

but fbDidLogin is never called.

EDIT

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

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

[facebook setPermission:@"offline_access"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM