Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how i can authenticate Facebook access token using xmppstream object in iPhone

Tags:

iphone

xmpp

I am developing Facebook chat application using xmppframework.I got Facebook access token but
this access is not authenticate by xmppstream object:

Here is my setupStream method

- (void)setupStream
{
   XMPPStream *xmppStream=[[XMPPStream alloc] initWithFacebookAppId:@"443170809037796"];
}   

here is my connection method

-(BOOL)connect1
{
    NSLog(@"connect1");
    NSError *error = nil;
    if(![xmppStream isDisconnected]) 
    {
        NSLog(@"isDisconnected");
        return YES;
    } 
    if (![xmppStream connect:&error])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error connecting fb" 
                                                            message:@"See console for error details."
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok" 
                                                  otherButtonTitles:nil];
        [alertView show];   
        return NO;
    }
    return YES;
}

here is my xmppStreamDidconnect delegate method for authentication

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    isXmppConnected = YES;
    NSError *error = nil;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [xmppStream authenticateWithFacebookAccessToken:[defaults             objectForKey:@"FBAccessTokenKey"] error:&error];        
}

when I run this app I am getting the fallowing error

didNotAuthenticate

Can any one solve my problem plz.

like image 264
venkat Avatar asked Jul 12 '12 11:07

venkat


People also ask

How do I verify my Facebook access token?

You can simply request https://graph.facebook.com/me?access_token=xxxxxxxxxxxxxxxxx if you get an error, the token is invalid. If you get a JSON object with an id property then it is valid. Unfortunately this will only tell you if your token is valid, not if it came from your app.

How can I get my Facebook ID and access token?

To get a Page access token, send a GET request to the /PAGE-ID endpoint using your User access token. Replace PAGE-ID and USER-ACCESS-TOKEN with your information. If you used a short-lived User access token, the Page access token is valid for 1 hour.

What is FB Accesstoken?

Access tokens generated via web login are short-lived tokens, but you can convert them to long-lived tokens by making a server-side API call along with your app secret. Mobile apps that use Facebook's iOS and Android SDKs get long-lived tokens by default.

How do I get a short live access token on Facebook?

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left. Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.


1 Answers

facebook chat uses secure connection thus connect method should look like this

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);

    isXmppConnected = YES;

    NSError *error = nil;
    //facebook connection
    if (_streamType == AAConnectStreamTypeFacebook) {

        if (![xmppStream isSecure])
        {

            NSError *error = nil;
            BOOL result = [xmppStream secureConnection:&error];

            if (result == NO)
            {
                DDLogError(@"%@: Error in xmpp STARTTLS: %@", THIS_FILE, error);

            }
        }
        else
        {

            NSError *error = nil;
            BOOL result = [xmppStream authenticateWithFacebookAccessToken:FBSession.activeSession.accessTokenData.accessToken error:&error];

            if (result == NO)
            {
                DDLogError(@"%@: Error in xmpp auth: %@", THIS_FILE, error);

            }
        }
    }
    else if (![[self xmppStream] authenticateWithPassword:password error:&error])
    {

        DDLogError(@"Error authenticating: %@", error);
    }
}
like image 118
Chamira Fernando Avatar answered Nov 15 '22 08:11

Chamira Fernando