Skip to content

Latest commit

 

History

History
72 lines (53 loc) · 2.9 KB

README.md

File metadata and controls

72 lines (53 loc) · 2.9 KB

Automate social media posts

The background

A part of our workflow at Abandoned Hope is:

  1. Post YouTube video with custom thumbnail, video title and description
  2. Share this on all social media (Twitter, Facebook and IGTV) manually

This takes our certain time which can be automated without errors which we often commit while copy pasting cross platforms. This inspired me to write this script to automate (at least) Twitter's part for now.

How this works

Using YouTube's API calls, this will fetch metadata from the latest video including video title, high-res thumbnail and the description and post a tweet with a picture and link to YouTube's video. In our videos, we separate the last line of the video description as the hashtags (as most of us) making it easier to scrape them using regex: hashtags = re.split("\n", description)[-1]

Pre-reqs

  1. Get YouTube Channel ID from https://www.youtube.com/account_advanced
  2. Google developer account with API keys. If you don't have it yet or misplaced the keys, generate it here: https://developers.google.com/youtube/v3/getting-started
  3. Twitter developer account with API keys from https://developer.twitter.com/

Installation

  1. The Google APIs Client Library for Python:
pip install --upgrade google-api-python-client
pip install --upgrade google-auth-oauthlib google-auth-httplib2
  1. Tweepy API for twitter:
pip install tweepy
  1. Clone this repo:
git clone https://github.com/shreyasgaonkar/social-media-posts.git
  1. Rename config.sample.json to config.json
  2. Update config.json with your developer keys from Twitter and YouTube:
{
    "youtube_channel_id": "XXXX",
    "youtube_API_key": "XXXX",
    "twitter_API_Key": "XXXX",
    "twitter_secret_key": "XXXX",
    "twitter_bearer_token": "XXXX",
    "twitter_access_token": "XXXX",
    "twitter_access_token_secret": "XXXX"
}
  1. Run python app.py to post thumbail image from your latest video

Issues

If you run into this error: AttributeError: 'Http' object has no attribute 'http' , refer to the solution here: googleapis/google-api-python-client#1046

Customize tweet

Replace this section from app.py to what fits your use-case and Twitter's character count:

# Custom status message
status = f"{title}\n\nNew Video out now! \n\n {video_url} \n\n {hashtags}"

Output:

Sample Tweet

Missing Info / Bugs

  • 😰 Something broken? Open an issue with additional context and I'll try to fix it. Screenshots help!

  • More additional services/use-cases, open a new issue