Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
long lived facebook access token
#!/usr/bin/env sh
# Turn a short-lived access token into a long(er) lived access token.
# To use this you must first generate a short-lived access token using the
# graph API (
# NOTE: make sure you select your app under the "Application" dropdown. if you
# don't you will see an error from this saying something about your app and
# not having permission/access
# SEE:
: ${FACEBOOK_APP_ID:="your app client id"}
: ${FACEBOOK_APP_SECRET:="your app client secret"}
: ${FBAPIV:="v2.6"}
do_request() {
local url="${1}"
curl -D /dev/stderr -s "${url}" | awk -F'&' '{print $1}' | awk -F= '{print $2}'
refresh_token() {
local token="${1}"
local url="${FBAPIVS}/oauth/access_token?grant_type=fb_exchange_token&client_id=${FACEBOOK_APP_ID}&client_secret=${FACEBOOK_APP_SECRET}&fb_exchange_token=${token}"
do_request "${url}"
usage() {
echo "Usage: $(basename $0) <short-lived-token>"
exit 1
main() {
local token="${1}"
refresh_token "${token}"
if [ $# -eq 0 ]; then
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.