agorapulse / grails-facebook-sdk

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

exchangeToken returns null #52

Closed confile closed 11 years ago

confile commented 11 years ago

I have a valid access token

def accessToken = facebookContext.user.token

When I request an exchange Token I got null

def exchangeToken = facebookContext.user.exchangeToken()

What do I have to do to get the exchange Token?

benorama commented 11 years ago

Indeed, exchangeToken() does not return any value. It sets the corresponding properties in ContextUser.

println "Old token $facebookContext.user.token"
println "Old expiration time ${new Date(facebookContext.user.tokenExpirationTime)}"

facebookContext.user.exchangeToken()

println "New token $facebookContext.user.token"
println "New expiration time ${new Date(facebookContext.user.tokenExpirationTime)}"
confile commented 11 years ago

@benorama

I use your code above and I get the following:

grails> Old token AAAEqZBHQL4O8BAMo1ZCaZABi0rZAUIRs3yZBsBrVBqPjOiQBvCZCIzNaqNnxIZCPqvcKr5cIZBZCEDYlVdByN4wJ3r1vAe7aMnVZBZCWlMEfHQBPgZDZD
grails> Old expiration time Sat Apr 06 00:24:14 CEST 2013
grails> New token AAAEqZBHQL4O8BAMo1ZCaZABi0rZAUIRs3yZBsBrVBqPjOiQBvCZCIzNaqNnxIZCPqvcKr5cIZBZCEDYlVdByN4wJ3r1vAe7aMnVZBZCWlMEfHQBPgZDZD
grails> New expiration time Sat May 25 17:27:01 CEST 2013

Why is the old and the new token the same? Is this correct?

benorama commented 11 years ago

May be the old token has been already exchanged? Could you try with a brand new Facebook session?

If you want to debug a token, you can use this great tool: https://developers.facebook.com/tools/debug/access_token

Enter the token, and it will give you the app/user/token and expiration info about this token.

confile commented 11 years ago

@benorama But when you look at the expiration time you see that they are different. How can this be even if the token is equal?

benorama commented 11 years ago

The first "old expiration time" is clearly not correct. How did you get it? Those value are stored in session server-side, there was perhaps a mismatch between old and new session.

You might start the authentication process from a fresh session (kill your cookies/browser) to see if you still have the issue.