Created
June 15, 2016 17:45
-
-
Save robhurring/b992fdf18b618db9a784add9ae55c175 to your computer and use it in GitHub Desktop.
long lived facebook access token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 (https://developers.facebook.com/tools/explorer/) | |
# | |
# 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: http://stackoverflow.com/questions/17197970/facebook-permanent-page-access-token | |
: ${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="https://graph.facebook.com/${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 | |
usage | |
fi | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment