Skip to content

Instantly share code, notes, and snippets.

@AtsushiSakai
Last active December 3, 2022 06:08
Show Gist options
  • Select an option

  • Save AtsushiSakai/4d29bc51194b280401907e85f73e888f to your computer and use it in GitHub Desktop.

Select an option

Save AtsushiSakai/4d29bc51194b280401907e85f73e888f to your computer and use it in GitHub Desktop.

Revisions

  1. AtsushiSakai revised this gist Dec 3, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions bitlyapi.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    #
    # Get access_token from: https://app.bitly.com/settings/api/
    # Then, just call this function with your long url and access token
    #
    # Ref
    # - https://dev.bitly.com/api-reference/#createBitlink
    # - https://dev.bitly.com/docs/getting-started/introduction/

    import requests

  2. AtsushiSakai renamed this gist Dec 3, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. AtsushiSakai created this gist Dec 3, 2022.
    16 changes: 16 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #
    # Get access_token from: https://app.bitly.com/settings/api/
    # Then, just call this function with your long url and access token

    import requests

    def get_shorten_url(long_url, access_token):
    url = 'https://api-ssl.bitly.com/v4/shorten'

    headers = {"Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
    }
    body = {'long_url':long_url}
    res = requests.post(url, headers=headers, json=body).json()
    return res["link"] # shorten url