2 Configuration - Reference Documentation
Authors: Benoit Hediard
Version: 2.3.0
2 Configuration
Installation
Declare the plugin dependency inBuildConfig.groovy file, as shown here:grails.project.dependency.resolution = {
inherits("global") { }
log "info"
repositories {
//your repositories
}
dependencies {
//your regular dependencies
}
plugins {
//here go your plugin dependencies
runtime ':facebook-sdk:2.3.0'
}
}Single Facebook app
Create a Facebook app on Facebook Developers , in order to get your own app ID and app secret.Add your app settings inConfig.groovy:// Required
grails.plugin.facebooksdk.app.id = {APP_ID}
grails.plugin.facebooksdk.app.permissions = {APP_PERMISSIONS} // Ex. ['email','user_photos']
grails.plugin.facebooksdk.app.secret = {APP_SECRET}
// Optional, default proxy config for Facebook Graph Client API calls
// grails.plugin.facebooksdk.proxyHost = {PROXY_HOST}
// grails.plugin.facebooksdk.proxyPort = {PROXY_PORT}grails {
plugin {
facebooksdk {
app = [
id: APP_ID,
permissions: APP_PERMISSIONS,
secret: APP_SECRET
]
}
}
}Multiple Facebook apps
Since V0.4, it is possible do define multiple apps inConfig.groovy:grails {
plugin {
facebooksdk {
appIdParamName = 'app_id' // Default app selection param name
apps = [
[
id: {APP_ID1},
permissions: {APP_PERMISSIONS1}, // Ex. ['email','user_photos']
secret: {APP_SECRET1}
],
[
id: {APP_ID2},
permissions: {APP_PERMISSIONS2}, // Ex. ['email','user_photos']
secret: {APP_SECRET2}
],
…
]
}
}
}app_id in params (by appending ?app_id={APP_ID} to query string) in order to specify which Facebook app setting to use.Note: to define another parameter name, set config param grails.plugin.facebooksdk.appIdParamName.You can also associate a Facebook app to a default controller by adding controller name in each app settings :grails {
plugin {
facebooksdk {
apps = [
[
controller: {CONTROLLER_NAME1},
id: {APP_ID1},
permissions: {APP_PERMISSIONS1},
secret: {APP_SECRET1}
],
[
controller: {CONTROLLER_NAME2},
id: {APP_ID2},
permissions: {APP_PERMISSIONS2},
secret: {APP_SECRET2}
],
…
]
}
}
}QuizController and SweepstakesController.Add controller: 'quiz' in quiz app settings and controller: 'sweepstakes' in sweepstakes app settings.To access your quiz app, use http://localhost:8080/my-app/quiz .To access your sweepstakes app, use http://localhost:8080/my-app/sweepstakes .If no app is found based on app_id params and controller name, default single app grails.plugin.facebooksdk.app settings will be used (if defined).
Graph API Version
By default, latest Graph API v2.3 will be used. You can override default settings withapiVersion config parameter :grails.plugin.facebooksdk.apiVersion = 'v2.2'
Session replication and authorization code
When using distributed session replication, if authorization code is used by two concurrent processes, one of the process will received an error from Facebook and the session will be invalidated. You can add thetokenRetrievalRetryCount config parameter to try to extract token from session several times before invalidating the session (the time for the first process to put the token received by Facebook into session scope).grails.plugin.facebooksdk.tokenRetrievalRetryCount = 10
Controllers scope
Since FacebookContext should be instantiated at each request, you must useprototype scope for your Controllers (since Grails 2.3, generated Config.groovy defines singleton as default scope).grails.controllers.defaultScope = 'prototype'
JQuery custom selector
Default jQuery selector is$, if you require another one, you can define it globally in your grails-app/conf/Config.groovy :grails.plugin.facebooksdk.customSelector = 'jQuery'