{"id":22832579,"url":"https://github.com/waldner/twitter-lib","last_synced_at":"2026-05-10T16:03:58.394Z","repository":{"id":92012187,"uuid":"127277965","full_name":"waldner/twitter-lib","owner":"waldner","description":"Shell library to do Twitter API calls","archived":false,"fork":false,"pushed_at":"2022-11-22T12:14:05.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T02:18:57.913Z","etag":null,"topics":["bash","shell","twitter","twitter-api"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waldner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-29T10:48:24.000Z","updated_at":"2022-11-22T12:14:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"74e885a7-7cb0-461b-8be7-c8d223a4c493","html_url":"https://github.com/waldner/twitter-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/waldner/twitter-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Ftwitter-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Ftwitter-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Ftwitter-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Ftwitter-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waldner","download_url":"https://codeload.github.com/waldner/twitter-lib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldner%2Ftwitter-lib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268272979,"owners_count":24223790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","shell","twitter","twitter-api"],"created_at":"2024-12-12T21:08:08.224Z","updated_at":"2026-05-10T16:03:53.364Z","avatar_url":"https://github.com/waldner.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# twitter-lib\nShell library to do Twitter API calls\n\n### What's this?\n\nThis is a barebones implementation of Twitter API [OAuth signing](https://developer.twitter.com/en/docs/basics/authentication/guides/creating-a-signature.html) and [request sending](https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request). It's a shell library that uses only **`bash`** and basic utilities. It can be used as a starting point to implement more complex Twitter application logics.\n\n## Dependencies\n\nThe only dependencies needed are [**`bash`**](https://www.gnu.org/software/bash/), [**`curl`**](https://curl.haxx.se/), **`awk`** (any version should work), [**`openssl`**](https://www.openssl.org/) for the crypto part, **`sort`** and GNU **`date`**.\n\n## Installation\n\nNo special installation needed. Just put **`twitter-lib.sh`** wherever you want. You have to know the location because you'll have to source it in your script.\n\n## Getting started\n\n- You need a [Twitter developer account](https://developer.twitter.com/) to use the API.\n\n- Create an application in your [Twitter apps control panel](https://apps.twitter.com). Name it whatever you want, and use a made-up return URL (eg, http://localhost/). It's not used here, but it has to be present.\n\n- Go to \"Keys and Access Tokens\" and get the following values: \"Consumer Key (API Key)\", \"Consumer Secret (API Secret)\" from the \"Application Settings\" section, and \"Access Token\" and \"Access Token Secret\" from the \"Your Access Token\" section.\n\n- Source **`twitter-lib.sh`** in your script\n\n- Implement a function called **`tt_get_userdef_credentials`** that sets the following environment variables with the corresponding values from your application: **`tt_lib['oauth_consumer_key']`**, **`tt_lib['oauth_consumer_secret']`**, **` tt_lib['oauth_token']`**, **`tt_lib['oauth_token_secret']`**. You can also optionally set **`tt_lib['user_agent']`** with the name of your app if you want, this will be set in API requests.\n\n- Call **`tt_do_call`** with the appropriate values to start using the API. See below for examples.\n\n## Logging\n\nSourcing the library gives you access to a very rudimentary log function called `tt_log`. Its arguments are a log level (one of  DEBUG, INFO, NOTICE, WARNING, ERROR) and the message to log. You can use this function to log your application messages together with those coming from the library. By default, the library detects automatically whether to log to file or to stdout (if stdout is not a terminal, log to file; otherwise log to stdout). This allows eg running from cron without getting output, but still being able to manually run on the command line and see the messages. The log destination can however be forced. The minimum logging level can also be configured, or logging can be turned off altogether. See code below for examples.\n\n## Internals\n\nAll the library setting are stored in a global associative array called **`tt_lib[]`**\n\nAfter each file API function invocation, the three variables **`tt_lib['last_http_headers']`**, **`tt_lib['last_http_body']`** and **`tt_lib['last_http_code']`** contain what their name says, so they can be inspected in your code for extra control.\n\n**`tt_do_call`** computes OAuth credentials for the request and ends up calling **`tt_do_curl`** with appropriate arguments.\n\n## Sample code\n\nNote: you might not be able to perform certain API calls, depending on the permission you assigned to your application.\n\nArguments to **`tt_do_call`** are: HTTP method, URL, arguments, in this order. See [the API reference](https://developer.twitter.com/en/docs/api-reference-index) for available API calls.\n\n```\n#!/bin/bash\n\n# you must implement this function with the right values\ntt_get_userdef_credentials(){\n  tt_lib['oauth_consumer_key']=\"xxxxxxxxxx\"\n  tt_lib['oauth_consumer_secret']=\"yyyyyyyyyyyyyyy\"\n  tt_lib['oauth_token']=\"zzzzzzzzzzzzzzzzzzzz\"\n  tt_lib['oauth_token_secret']=\"wwwwwwwwwwwwwwwwwwwww\"\n  tt_lib['user_agent']=\"My Super Twitter App/1.0\"    # optional\n}\n\n. /path/to/twitter-lib.sh\n\n# OPTIONAL: configure logging\n\n# tt_set_log_level DEBUG        # valid values: DEBUG, INFO, NOTICE, WARNING], ERROR\n# tt_set_logging_enabled 1      # valid values: 0 = logging disabled, anything else = enabled\n# tt_set_log_destination file   # valid values: file = log to file, stdout = log to stdout (doh!)\n                                # default file: /tmp/tt_YYYY-MM-DD_hh:mm:ss.log\n\n############### Get user information\nuser_id=\"123456789\"\ntt_do_call GET \"https://api.twitter.com/1.1/users/show.json\" \"user_id=${user_id}\" \"include_entities=false\"\n\nif [ $? -ne 0 ]; then\n  # Error preventing the call from being made\n  tt_log ERROR Terminating\n  exit 1\nfi\n\nif [ \"${tt_lib['last_http_code']}\" != \"200\" ]; then\n  tt_log ERROR \"Error getting user details\" \n  # inspect ${tt_lib['last_http_headers']}, ${tt_lib['last_http_body']} etc\nelse\n  user_name=$(jq -r '.name' \u003c\u003c\u003c \"${tt_lib['last_http_body']}\")\n  user_screen_name=$(jq -r '.screen_name' \u003c\u003c\u003c \"${tt_lib['last_http_body']}\")\n  user_description=$(jq -r '.description' \u003c\u003c\u003c \"${tt_lib['last_http_body']}\")\n  user_followers=$(jq -r '.followers_count' \u003c\u003c\u003c \"${tt_lib['last_http_body']}\")\n  # etc.\nfi\n\n############### Publish a tweet\n\ntweet_text=\"This is a tweet submitted via the API.\"\ntt_do_call POST \"https://api.twitter.com/1.1/statuses/update.json\" \"status=${tweet_text}\"\n\nif [ $? -ne 0 ]; then\n  # Error preventing the call from being made\n  tt_log ERROR Terminating\n  exit 1\nfi\n\nif [ \"${tt_lib['last_http_code']}\" != \"200\" ]; then\n  tt_log ERROR \"Error submitting tweet\"\n  # inspect ${tt_lib['last_http_headers']}, ${tt_lib['last_http_body']} etc\nelse\n  tweet_id=$(jq -r '.id_str' \u003c\u003c\u003c \"${tt_lib['last_http_body']}\")\n  # etc.  \nfi\n\n############### Get user timeline\n\n# Error checking omitted for brevity\n\nuser_id=\"123456789\"\ntweet_count=100\ntt_do_call GET \"https://api.twitter.com/1.1/statuses/user_timeline.json\" \"user_id=${user_id}\" \"count=${tweet_count}\"\n\n# print all tweets\nwhile IFS= read -r tweet; do\n  jq -r '.text' \u003c\u003c\u003c \"$tweet\"\n  echo \"----------\"\ndone \u003c \u003c(jq -c '.[]' \u003c\u003c\u003c \"${tt_lib['last_http_body']}\")\n\n# ...more API calls here...\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaldner%2Ftwitter-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaldner%2Ftwitter-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaldner%2Ftwitter-lib/lists"}