Ad

Graph API With App Token For Page Not Working

- 1 answer

I'm developing an app with Login with Facebook and also Login with username and password.

Now i want to find all the events of a public page on Facebook for both the types of users (Facebook and Normal).

The problem is that the User with Facebook can retrieve the data, but the "normal" user cannot because data is nil.

The steps are :

1 - Compile this url with the correct credential of my Facebook App :

https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=client_credentials

2 - Put the url in my browser and retrieve the App Token In the format :

53682XXXXXXXXXX|w6F3Ic6L48XXXXXXXXXXXXXXXXX

3 - Use this piece of code :

NSString *token = [[[FBSession activeSession] accessTokenData] accessToken];
NSString *urlString;
        if (!userWithFb) {
            NSString *token = @"53682XXXXXXXXXX|w6F3Ic6L48XXXXXXXXXXXXXXXXX";
            urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/events?access_token=%@", pageId,token];
        }else{
            urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/events?access_token=%@", pageId,token];
        }

        NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
        if(data != nil)
            [self performSelectorOnMainThread:@selector(fetchedData:)
                                   withObject:data waitUntilDone:YES];

BUT the data for the normal user is nil. When I put the "urlstring" in my browser I see all the data , I don't know where is the problem. Waiting for solution I say thanks.

Ad

Answer

I solved my question by adding this piece of code after the if statement :

NSString *encodedURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
        url = [NSURL URLWithString:encodedURLString];

        NSData* data = [NSData dataWithContentsOfURL:url];

The Problem is the "|" in the token, it must be replaced with "&".

Hope this help you !

Ad
source: stackoverflow.com
Ad