-
Notifications
You must be signed in to change notification settings - Fork 3
4. Generate an Access Token
Faris edited this page Oct 18, 2017
·
2 revisions
This page will guide you about how to generate an access token.
- Please get your application id and also application secret from your application dashboard.
package main
import (
"fmt"
facebook "github.com/madebyais/facebook-go-sdk"
)
func main() {
// initalize facebook-go-sdk
fb := facebook.New()
// set your application id (client_id)
fb.SetAppID(`{APP_ID}`)
// set your application secret (client_secret)
fb.SetAppSecret(`{APP_SECRET}`)
// Call https://www.facebook.com/v2.10/dialog/oauth?client_id={APP_ID}&redirect_uri={YOUR_REDIRECT_URI}
// And then, retrieve the `code` value from {YOUR_REDIRECT_URI}?code=....
// Then call GenerateAccessToken(redirectURI string, code string) method
data, err := fb.GenerateAccessToken(`{YOUR_REDIRECT_URI}`, `{GENERATED_CODE}`)
if err != nil {
panic(err)
}
// print data object
fmt.Printf(`%+v`, data)
fmt.Println(data["access_token"])
}