Skip to content

Instantly share code, notes, and snippets.

@vitouXY
Last active November 6, 2022 03:25
Show Gist options
  • Save vitouXY/db7dbf3c0463288a46f439cc25a5822c to your computer and use it in GitHub Desktop.
Save vitouXY/db7dbf3c0463288a46f439cc25a5822c to your computer and use it in GitHub Desktop.
Mastodon - Client Access Token - App & Bot
grep -v '^#' ${0}
exit 2
# https://docs.joinmastodon.org/client/token/#example-authorization-code-flow
# https://tinysubversions.com/notes/mastodon-bot/
## --- STEP 01/06 - get client_id and client_secret
MSTDN_SERVER=mastodon.world
MSTDN_SERVER=
APP_NAME=app_mstdn
APP_NAME=
APP_WEBSITE=http://example.cl
APP_WEBSITE=
## scope 'read write follow push'
curl -X POST -F "client_name=${APP_NAME:?}" -F 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' -F 'scopes=read write' -F "website=${APP_WEBSITE:-}" https://${MSTDN_SERVER:?}/api/v1/apps
##_ {"id":"18405","name":"APPNAME","website":null,"redirect_uri":"urn:ietf:wg:oauth:2.0:oob","client_id":"A0BCfefgHijklMnOpqrsTUVwXyz1abcdeFG23HIJKLM","client_secret":"01ab_cdefGhI-2j34KlMNo-pqRstuV5WxYZAB6cdEfG","vapid_key":""}
## --- STEP 02/06 - authorize and get authorization_code
##IENT_ID=A0BCfefgHijklMnOpqrsTUVwXyz1abcdeFG23HIJKLM
CLIENT_ID=
##IENT_SECRET=01ab_cdefGhI-2j34KlMNo-pqRstuV5WxYZAB6cdEfG
CLIENT_SECRET=
## curl -X POST -F "client_id=${CLIENT_ID:?}" -F "client_secret=${CLIENT_SECRET:?}" -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -F 'grant_type=client_credentials' https://${MSTDN_SERVER:?}/oauth/token
##_ {"access_token":"OAb-CDEFGHiJ1KlMn_OPqrsT2U3_VX4y5ZaBce6e7Fg","token_type":"Bearer","scope":"read","created_at":1667688960}
echo -e "* SignIn from the Browser. Then go to...\n[ https://${MSTDN_SERVER:?}/oauth/authorize?client_id=${CLIENT_ID:?}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=read+write ]\n ...and AUTHORIZE."
##_ 0a1bCdefgh23ijk4lm5nOPQrSTU6VwxTzaBCdef-7GH
## --- STEP 03/06 - get access_token
##THORIZATION_CODE=0a1bCdefgh23ijk4lm5nOPQrSTU6VwxTzaBCdef-7GH
AUTHORIZATION_CODE=
curl -X POST -F "client_id=${CLIENT_ID:?}" -F "client_secret=${CLIENT_SECRET:?}" -F "code=${AUTHORIZATION_CODE:?}" -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -F 'grant_type=authorization_code' https://${MSTDN_SERVER:?}/oauth/token
##_ {"access_token":"OAb-CDEFGHiJ1KlMn_OPqrsT2U3_VX4y5ZaBce6e7Fg","token_type":"Bearer","scope":"read write","created_at":1667686443}
## --- STEP 04/06 - Test
##CESS_TOKEN=OAb-CDEFGHiJ1KlMn_OPqrsT2U3_VX4y5ZaBce6e7Fg
ACCESS_TOKEN=
curl -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/apps/verify_credentials
##_ {"name":"APPNAME","website":null,"vapid_key":""}
## --- STEP 05/06 - Send status
# https://docs.joinmastodon.org/methods/statuses/
## visibility: public/unlisted/private/direct
TEXT_TITLE=""
TEXT="Hi! this is a test!"
TEXT=""
curl -F "status=${TEXT:?}" -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses
curl -F "status=${TEXT:?}" -F "sensitive=true" -F "spoiler_text=${TEXT_TITLE:?}" -F "visibility=private" -F "language=es" -H "Idempotency-Key: $(date +%Y%m%d)" -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses
##_ {"id":"123456789098765432","created_at":...
STATUS_ID=123456789098765432
curl -X GET -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses/${STATUS_ID:?}
curl -X DELETE -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses/${STATUS_ID:?}
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses/${STATUS_ID:?}/favourite
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses/${STATUS_ID:?}/unfavourite
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses/${STATUS_ID:?}/pin
curl -X POST -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses/${STATUS_ID:?}/unpin
##_ {"id":"123456789098765432","created_at":...
## --- STEP 06/06 - Send status with media
# https://docs.joinmastodon.org/methods/statuses/media/
# # https://mastodonpy.readthedocs.io/en/stable/
MEDIA_FILE=imagefile01.png
MEDIA_FILE=
DESCRIPTION="Just a image - 01"
DESCRIPTION=""
curl -F "file=@${MEDIA_FILE:?}" -F "description=${DESCRIPTION:?}" -F "focus=0,0" -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/media
##_ {"id": "987654321012345678","type": "image",...
##DIA_ID1=987654321012345678
MEDIA_ID1=
##DIA_ID2=987654321023456789
MEDIA_ID2=
##DIA_ID3=987654321034567899
MEDIA_ID3=
##DIA_ID4=987654321045678998
MEDIA_ID4=
TEXT_TITLE=""
TEXT=""
curl -F "status=${TEXT:?}" -F "media_ids[]=${MEDIA_ID1:?}" -F "sensitive=1" -F "spoiler_text=${TEXT_TITLE:?}" -F "visibility=private" -F "language=es" -H "Idempotency-Key: $(date +%Y%m%d)M" -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses
curl -F "status=${TEXT:?}" -F "media_ids[]=${MEDIA_ID1:?}" -F "media_ids[]=${MEDIA_ID2:?}" -F "media_ids[]=${MEDIA_ID3:?}" -F "media_ids[]=${MEDIA_ID4:?}" -F "sensitive=1" -F "spoiler_text=${TEXT_TITLE:?}" -F "visibility=private" -F "language=es" -H "Idempotency-Key: $(date +%Y%m%d)M" -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/statuses
##_ {"id":"123456789098765432","created_at":...
## --- get statuses
##COUNT_ID=091827364554637281
ACCOUNT_ID=
curl -X GET -H "Authorization: Bearer ${ACCESS_TOKEN:?}" https://${MSTDN_SERVER:?}/api/v1/accounts/${ACCOUNT_ID:?}/statuses
#_ [{...},{...}]
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment