agorapulse / grails-facebook-sdk

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

Other Facebook Graph objects not working #54

Closed james-bw closed 11 years ago

james-bw commented 11 years ago

I'm trying to get other Facebook graph connections and they seem to fail. E.g. statuses, checkins, photos and albums. I would expect the following to work and they don't:

def index() {
    FacebookGraphClient facebookGraphClient = new FacebookGraphClient()
    def user
    List userFriends = []
    List userPhotos
    List userAlbums
    List checkins = []
    List statuses = []
    if (facebookContext.app.id && facebookContext.authenticated) {
        String token = facebookContext.user.token
        if (token) {
            facebookGraphClient = new FacebookGraphClient(token)
            try {
                user = facebookGraphClient.fetchObject(facebookContext.user.id.toString())
                userFriends = facebookGraphClient.fetchConnection("${facebookContext.user.id}/friends", [limit:10])
                checkins = facebookGraphClient.fetchConnection("${facebookContext.user.id}/checkins")
                statuses = facebookGraphClient.fetchConnection("${facebookContext.user.id}/statuses")
                userPhotos = facebookGraphClient.fetchConnection("/me/photos", [limit:10])
                userAlbums = facebookGraphClient.fetchConnection("/me/albums", [limit:10])
                log.debug("Friends are: " + userFriends)
                log.debug("Photos are: " + userPhotos)
                log.debug("Albums are: " + userAlbums)
                log.debug("Checkins are: " + checkins)
                log.debug("Statuses are: " + statuses)
            } catch (FacebookOAuthException exception) {
                facebookGraphClient = new FacebookGraphClient() // Do not use invalid token anymore
                facebookContext.user.invalidate()
            }
        }
    }
james-bw commented 11 years ago

Actually not an issue with the SDK, it was resolved by adding the following to the config:

grails.plugin.facebooksdk.appPermissions = 'email,user_photos,user_status,publish_actions'

It would be nice to see this in the documentation.

benorama commented 11 years ago

Hi James,

Indeed, I've updated the doc. http://benorama.github.io/grails-facebook-sdk/guide/facebookGraphClient.html

Thanks.