ã¯ããã«
ð£ãªã§ã¼ã¹ã±ããããããããï¼ ï¼ç§ã¯ï¼nikkieã§ãã
URLãç縮ã§ãããµã¼ãã¹Bitlyã
Web APIãå
¬éããã¦ãã¾ãã
APIã使ã£ã¦back-halfï¼http://bit.ly/XXX
ã®XXX
ã®é¨å1ï¼ãæå®ããURLãä½ãæ¹æ³ãã¢ã¦ãããããã¾ãã
ç®æ¬¡
- ã¯ããã«
- ç®æ¬¡
- ãããããã¨ã®å§ã¾ãã¯
- ç»é¢æä½ç·¨
- Web APIã使ã£ãèªååç·¨
- è¦å´è©±
- çµããã«
ãããããã¨ã®å§ã¾ãã¯
èæ¯
ãback-halfãæå®ããç縮URLãBitlyã®APIãä»ãã¦ä½ããããã¯ãã¿ããªã®Pythonåå¼·ä¼ã®ã¹ã¿ããæ´»å2ã®ä¸ç°ã§ãã
åå¼·ä¼ã§ã¯http://bit.ly/stapy94awesome
ã®ãããªç縮URLã使ã£ã¦ãã¾ã3ã
ç¨èªã®æ´ç
http://bit.ly/stapy94awesome
ã®ãããªç縮URLã§ãããBitlyã®ç¨èªã§ã¯ãShort link with a custom back-halfãã¨å¼ã¶ããã§ãã
https://support.bitly.com/hc/en-us/articles/115001626408
- ãã¡ã¤ã³ã¯
bit.ly
- back-halfï¼ãURLã®å¾ãååãã ã¨æãã¾ãï¼ã
stapy94awesome
ã¨customize- back-halfãæå®ããªãã¨ãBitlyãããæãã«ã©ã³ãã ãªæååã§ä»ãã¦ããã¾ã
åæ°å¶éã¯ããã¾ãããç¡æã§ãå©ç¨ã§ãã¾ãã
ä»å試ãä¸ã§ç¥ã£ãã®ã§ããããShort link with a custom back-halfãã¯ï¼å°ãªãã¨ãç¡æãã©ã³ã§ã¯ç»é¢æä½ã§ï¼æ¶ããªãããã§ãï¼ä¸è¦§ããé ããã¨ã¯ã§ãã¾ãï¼4ã
ç»é¢æä½ç·¨
- Bitlyã«ãã°ã¤ã³
- ãCreate newã > ãLinkã
- 以ä¸ãå
¥å
- ãDestinationãã«ç縮ãããé·ãURL
- ãCustom back-halfãã«æå®ãããæåå
Web APIã使ã£ãèªååç·¨
ç»é¢æä½ã§ã§ããã®ãªããå ¬éããã¦ããAPIãï¼ç»é¢ãã使ãã®ã¨åæ§ã«ï¼å©ç¨ãã¦ãèªååãããã¨èãã¾ããï¼æ æ°ã§ãããï¼ã
ã¢ã¯ã»ã¹ãã¼ã¯ã³åå¾
使ãåºãã¾ã§ã¯ä»¥ä¸ãåãããããã£ãã§ãã
- https://app.bitly.com/settings/api/ ã«ã¢ã¯ã»ã¹
- ã¢ã¯ã»ã¹ãã¼ã¯ã³ãçæ
- æ§ãã¦ããã¾ããã
curl
ã§å®è£
2ã¤ã®ã¨ã³ããã¤ã³ããå©ãã¾ãã
- POST
/v4/shorten
- https://dev.bitly.com/api-reference/#createBitlink
- back-halfã¯ã©ã³ãã ãªæååã§ç縮
- 2ã®å¼ã³åºãã§idã使ã
- POST
/v4/custom_bitlinks
- https://dev.bitly.com/api-reference/#addCustomBitlink
- idãæå®ãã¦back-halfãcustomize
% curl -H "Authorization: Bearer ${BITLY_ACCESS_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{"long_url": "https://nikkie-ftnext.hatenablog.com/entry/the-solitary-castle-in-the-mirror-2023-june"}' \ https://api-ssl.bitly.com/v4/shorten | jq . # è¿ãå¤ã®JSONã®.idãå¾ç¶ã®å¼ã³åºãï¼-dã®.bitlink_idï¼ã§ä½¿ç¨ % curl -H "Authorization: Bearer ${BITLY_ACCESS_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{"custom_bitlink": "bit.ly/nikkie-api-practice", "bitlink_id": "bit.ly/3WRejsH"}' \ https://api-ssl.bitly.com/v4/custom_bitlinks | jq .
ã©ã³ãã ãªæååã«ããback-halfã®ã¨ã¤ãªã¢ã¹ã¨ãã¦ãã«ã¹ã¿ãã¤ãºããback-halfãæãããã¨ãããã¨ã§ãããããã
Pythonã¹ã¯ãªãã
Python 3.10.9ãæ¨æºã©ã¤ãã©ãªã ãã§å®è£ ãã¦ãã¾ãã
# ç°å¢å¤æ° BITLY_ACCESS_TOKEN ãè¨å®æ¸ã¿ % python create_custom_bitlink.py \ https://nikkie-ftnext.hatenablog.com/entry/the-solitary-castle-in-the-mirror-disk-advent-2023-start \ kagami-advent-2023
åå¼·ä¼éå¶èªååãªãã¸ããªã«ãå ¥ãã¾ããã
è¦å´è©±
ãã¥ã¼ããªã¢ã«ã®ããã¥ã¡ã³ãã®éãã«ãããããããã¾ããã
ãCreating custom linksãã«ã¯ä»¥ä¸ã®ããã«ããã¾ãã
To customize the back-half of a link, you'll perform an additional PATCH call.
PATCH /v4/custom_bitlinks/{custom_bitlink}
ã§ãããå©ãã¦ã¿ãã¨ã¨ã©ã¼ãè¿ã£ã¦ãã¾ãã
% curl -H "Authorization: Bearer ${BITLY_ACCESS_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{"bitlink_id": "bit.ly/nikkie-api-practice"}' \ -X PATCH https://api-ssl.bitly.com/v4/custom_bitlinks/bit.ly/3WRejsH | jq . { "message": "NOT_FOUND", "resource": "custom_bitlinks", "description": "What you are looking for cannot be found." }
ãã®ã¨ã©ã¼ã®ç¾æç¹ã®ç解ã§ããã
- PATCHãªã®ã§1ã¤ä»¥ä¸custom bitlinkï¼ãªã½ã¼ã¹ï¼ãåå¨ãã¦ããå¿ è¦ããã
- ã«ããããããã0åãªã®ã§not foundã¨ã©ã¼
ã¨ãããã¨ã§ããããã
ãã³ãã«ãªã£ãã®ã¯ãä»ã®è¨èªã§æ¸ãããã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªãçºãã¦ãã¦ã
GitHub - opsmatters/bitly-java-api: Java client library to execute operations on URLs using the Bitly API.
ãããè¦ã¦ãããããPATCHããã¨ã³ããã¤ã³ããPREMIUMï¼ããããææãã©ã³éå®ã®æï¼ã¨æ°ä»ãã¨ã¨ãã«ãPOSTãã¦custom bitlinkã1ã¤ä½ãï¼PREMIUMã§ãªãï¼ã¨ã³ããã¤ã³ãã®åå¨ã«æ°ä»ãã¾ããï¼
çµããã«
curlãPythonã§ãBitlyã®ç縮URLï¼ãã ããback-halfãæå®ãããã®ï¼ãä½ãæ¹æ³ãã¢ã¦ãããããã¾ããã
2ã¤ã®ã¨ã³ããã¤ã³ããé ã«å©ããã¨ã§å®ç¾ã§ãã¾ãã
ãã¥ã¼ããªã¢ã«ã®éãã«é²ãã¦ãã¨ã©ã¼ã¨ãªã£ããã¨ã§ãããã¾ãããã/v4/custom_bitlinks
ã¸ã®POSTã«æ°ã¥ãã¦ããããããã¨ãå®ç¾ã§ãã¾ããð
次åã®ã¿ããªã®Pythonåå¼·ä¼ã¯6/15(æ¨)ã§ãã
6æã¯ç°å¢æéããããstapyãç°å¢ã«ãã©ã¼ã«ã¹ãã¾ãï¼
- Bitlyã®APIãªãã¡ã¬ã³ã¹ã§ã¯ã¾ã è¦ã¤ãããã¦ãã¾ããããä¸è¬ã«ã¯slugã¨å¼ã¶ããããªããã¨æãã¾ã↩
- éå»è¨äºãã 週末ログ | みんなのPython勉強会のアーカイブ動画をトリミングしてからYouTubeにアップロードしました #stapy - nikkie-ftnextの日記↩
- connpassã®ãåå è ã¸ã®æ å ±ãã§è¦ããã¾ã↩
- ç»é¢ããæ¶ããã®ã¯back-halfãcustomizeãã¦ããªãç縮URLã ãã§ãããå®è£ ä¸ã«ä½ã£ãç縮URLãçä»ãã¦ãã¦æ°ã¥ãã¾ãã↩