Created
February 19, 2020 17:59
-
-
Save fmnxl/369269039e25ad80534cd3e17ba4b233 to your computer and use it in GitHub Desktop.
Facebook API access token generator
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
#!/bin/sh | |
heroku_app=my-app | |
client_id=XXXX | |
client_secret=XXXX | |
redirect_uri=https://example.com/ | |
generateAccessToken() { | |
http https://graph.facebook.com/v6.0/oauth/access_token \ | |
client_id=="${client_id}" \ | |
redirect_uri=="${redirect_uri}" \ | |
client_secret=="${client_secret}" \ | |
code=="$1" | \ | |
jq -r '.access_token' | |
} | |
generateLongLivedAccessToken() { | |
http https://graph.facebook.com/v6.0/oauth/access_token? \ | |
grant_type==fb_exchange_token \ | |
client_id=="${client_id}" \ | |
client_secret=="${client_secret}" \ | |
fb_exchange_token==$1 | \ | |
jq -r '.access_token' | |
} | |
code=${1} | |
if [ -z $code ]; then | |
echo "=> Obtain code" | |
oauth_url="https://www.facebook.com/v6.0/dialog/oauth?client_id=${client_id}&redirect_uri=${redirect_uri}" | |
echo "Going to ${oauth_url}" | |
open $oauth_url | |
read -p "Enter code: " code | |
fi | |
access_token=$(generateAccessToken $code) | |
long_lived_token=$(generateLongLivedAccessToken $access_token) | |
echo $long_lived_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment