views:

68

answers:

3

Hi all

Dunno if Im missing something but here goes. Im trying to get an access_token for my application so that it can go and look up events for certain public groups on facebook, without requiring a user to be logged in.

Im trying to get an access_token from https://graph.facebook.com/oauth/access_token?client_secret=foobar&client_id=foobar&grant_type=client_credentials&format=json&sdk=ios

This returns a string: access_token=xxxx|ugtqdoWfvvo5_S-Fo2D7_I4rdbc

Thats nice and all, but its no json. Any insights on why the returned string is not json encoded ?

Note: Im using the Facebook ios SDK function like so [_facebook requestWithGraphPath:@"oauth/access_token" andParams:params andHttpMethod:@"POST" andDelegate:self];

A: 

Any insights on why the returned string is not json encoded ?

Yeah, the access token isn't supposed to be JSON-encoded. And there's arguably little value in JSON-encoding a single string anyway.

Why are you expecting it to be so?

Peter Bailey
So you´re saying we need to write our own parsers then to handle the response?
H. Jensen
Now I'm confused - you don't need to parse the access token for anything that I know of. What are you trying to get out of parsing the access token?
Peter Bailey
A: 

If you're using Facebook SDK, I believe that they return NSArray and NSDictionnary

I might be wrong, but try with an objectForKey:@"access_token"

Thomas Joulin
A: 

Follow up.

The way I understand the FB ios SDK is that your delegate function will receive an object such as NSArray or NSDictionnary to work with. Looking into the internals of the FB SDK classes it seems that all response are parsed using the SBJSON parser. If the response is not json than that will fail.

[_facebook requestWithGraphPath:@"261247595170" andDelegate:self]; returns nice json. No problems there.

[_facebook requestWithGraphPath:@"oauth/access_token" andParams:params andHttpMethod:@"POST" andDelegate:self]; String returned. SBJSON parser fails.

This seems to be an inconsistency in the FB graph service.

One could write a special function to handle this problem, but if FB decides to change the format of the string, then all IPhone App would stop working, and need to update. Not cool.

H. Jensen