agorapulse / grails-facebook-sdk

Facebook SDK Grails Plugin
http://agorapulse.github.com/grails-facebook-sdk/guide
30 stars 13 forks source link

Can't get user access token #2

Closed cris150 closed 12 years ago

cris150 commented 12 years ago

I don't seem to get a valid user access token. I keep getting a null string. Here's my code:

if (userId) { println("User authenticated id="+userId) try { def userAccessToken = facebookAppService.getUserAccessToken() println userAccessToken

            facebookClient = new FacebookGraphClient(userAccessToken)        
            def checkins = facebookClient.fetchConnection("${request.facebook.user.id}/checkins")
            println checkins.size()

            def statuses = facebookClient.fetchConnection("${request.facebook.user.id}/statuses")
            println statuses[0]
        } catch(Exception ex){
            println ex
            facebookAppService.invalidateUser()
            facebookClient = new FacebookGraphClient()

        }

}

The error I'm getting: com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: An access token is required to request this resource.

benorama commented 12 years ago

Have you tried to run the Facebook-sdk-grails-demo located here : https://github.com/benorama/facebook-sdk-grails-demo

I've just downloaded it, update the conf, run the app and it worked fine. Can you give it a try ?

Where does it fail exactly in your code? You can also try to debug the userAccessToken here : https://developers.facebook.com/tools/debug

Check that you asked for the correct permissions ('user_checkins' and 'user_status').

cris150 commented 12 years ago

I'll try what you have suggested later this evening.

This is the line where it fails : def userAccessToken = facebookAppService.getUserAccessToken() It gives me a null string instead of the userAccessToken. I've asked for the correct permissions.

For the moment, I've manage to do a work-around, by manually parsing the "signed_request" parameter when somebody access the app. I get the access token and put it in the session scope and pass it afterwards to the FacebookGraphClient instance and it works.

Anyway, I'll update here after I try what you have suggested.

benorama commented 12 years ago

Any news on this issue?

benorama commented 12 years ago

Hi cris150,

FYI, I'm going to release pretty soon Facebook SDK V0.4. The main objective was to "clean" the SDK code which was pretty messy (since it was a port of PHP code...). The other objective was to be able to support multiple Facebook app within a single Grails app. It's pretty big refactoring of the code base.

Unfortunately, it won't be backward compatible with V0.3.* ... FacebookApp, FacebookSdkFilters and FacebookAppService have been deprecated and replaced by a single FacebookContext bean: a cleaner approach to access Facebook context info (current app, user, page...) So if you use any of them, you might have to do some refactoring on your app.

I'm looking for some feedback, if you have some time to play with it, it's on "develop" branch. You can download the updated docs here : http://cl.ly/2q2T300G201J

Thanks !

Ben