{"id":18318743,"url":"https://github.com/xdevplatform/pull-tweet-annotations-data-for-twitter-profiles","last_synced_at":"2025-09-15T14:06:54.061Z","repository":{"id":80527668,"uuid":"330950960","full_name":"xdevplatform/Pull-Tweet-Annotations-data-for-Twitter-profiles","owner":"xdevplatform","description":"Python code to identify most common topics mentioned by a Twitter profile, using Tweet Annotations and Recent Search API","archived":false,"fork":false,"pushed_at":"2021-01-19T14:36:03.000Z","size":20,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-05T21:36:55.125Z","etag":null,"topics":["annotations","python","tweet-annotations","twitter","twitter-api-v2","twitter-profiles"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xdevplatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-01-19T11:00:10.000Z","updated_at":"2025-03-10T18:28:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"1f31c9e2-f890-4679-80bb-a786d91a6716","html_url":"https://github.com/xdevplatform/Pull-Tweet-Annotations-data-for-Twitter-profiles","commit_stats":null,"previous_names":["xdevplatform/pull-tweet-annotations-data-for-twitter-profiles"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xdevplatform/Pull-Tweet-Annotations-data-for-Twitter-profiles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2FPull-Tweet-Annotations-data-for-Twitter-profiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2FPull-Tweet-Annotations-data-for-Twitter-profiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2FPull-Tweet-Annotations-data-for-Twitter-profiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2FPull-Tweet-Annotations-data-for-Twitter-profiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xdevplatform","download_url":"https://codeload.github.com/xdevplatform/Pull-Tweet-Annotations-data-for-Twitter-profiles/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2FPull-Tweet-Annotations-data-for-Twitter-profiles/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275267381,"owners_count":25434616,"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-09-15T02:00:09.272Z","response_time":75,"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":["annotations","python","tweet-annotations","twitter","twitter-api-v2","twitter-profiles"],"created_at":"2024-11-05T18:11:26.537Z","updated_at":"2025-09-15T14:06:54.037Z","avatar_url":"https://github.com/xdevplatform.png","language":"Python","readme":"# Pull Tweet annotations for Twitter profiles\n\nThis sample code pulls contextual information for given Twitter profiles, based on their recent Tweets (past 7 days), including: \n* Context annotations (annotation domains and annotation entities)\n* Entity annotations (people, places, products, and organisations)\n\nSpecifically, this code uses: \n* [The Twitter API v2 recent search endpoint](https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent)\n* [Tweet annotations](https://developer.twitter.com/en/docs/twitter-api/annotations)\n\nEach profile's Tweets are analysed, and the top most frequent annotation topics detected in their Tweets are returned in order of frequency. \n\nNote that this code does not paginate through the data returned by the API. As a result, no more than 100 Tweets will be analysed at any given time.\n\nThere are two scripts: \n* `main.py` returns both context annotations and entity annotations data, through the command line interface;\n* `data_to_csv.py` returns context annotations data in a CSV file. Does not return entity annotations.\n\n## Environment variables\n\nTo run this, you will first need to export your keys and tokens for your [Twitter developer App](https://developer.twitter.com/en/docs/apps/overview). Make sure to use an App that has access to the Twitter API v2. \n\nIn the command line, type the following lines of code. Replace each placeholder with your own credentials (without the `\u003c\u003e`).\n\n```\nexport 'API_KEY'='\u003cyour_api_key\u003e'\nexport 'API_SECRET'='\u003cyour_api_secret\u003e'\nexport 'API_TOKEN'='\u003cyour_api_token\u003e'\nexport 'API_TOKEN_SECRET'='\u003cyour_api_token_secret\u003e'\n```\n\n## `main.py`\n\nThis script returns context and entities annotations, via the command line interface, for a given Twitter profile (aka @username). You will be prompted to pass in the @username when you run the script.\n\nWhen present, entity annotations are analysed and returned. This means that specific people, places, products, organisations, or other topics that have been mentioned in the user's Tweets in the past week are displayed. These entities are only displayed if they have been categorised with a confidence score of 0.5 or higher.\n\nNote that, although 100% of Tweets are reviewed, due to the contents of Tweet text, only a portion are annotated.\n\nTo run this script:\n\n```\npython3 main.py\n```\n\n## `data_to_csv.py`\n\nThis script returns context annotations data in a CSV file (generates a file entitled `annotations.csv`) for a list of given usernames. \n\nTo pass in the usernames (aka @handles) for which you want to pull annotations data: populate the file entitled `Twitter_handles.csv` with the desired handles/usernames, without the @ (as per the example).\n\nYou may want to add `Twitter_handles.csv` to your `.gitignore` file.\n\nNote that this script does **not** return entity annotations.\n\nBy default, this script will return a CSV file with rows, each of which contains: \n* Given username\n* Number of Tweets sent in the past week (maximum 100)\n* Top 5 context annotation domains (and the number of times each of these was mentioned)\n* Top 5 context annotation entities (and the number of times each of these was mentioned) \n\nYou can change the number of top results returned towards the bottom of the script: \n\n```\n    max_count = 5   # Change number of top results displayed here\n```\n\nTo run this script:\n\n```\npython3 data_to_csv.py\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdevplatform%2Fpull-tweet-annotations-data-for-twitter-profiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxdevplatform%2Fpull-tweet-annotations-data-for-twitter-profiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdevplatform%2Fpull-tweet-annotations-data-for-twitter-profiles/lists"}