# Ultimate Guide to Automating Twitter/X Posts with AI

> Everyone wants to become an influencer or at least be active on social media nowadays, but we know it's not easy to plan, create, schedule, and post content every day. It's a headache for most people, and many don't even start their journey to becoming an influencer because of these hurdles. But don't worry, in this blog, I will explain how you can automate your Twitter/X account so that you only need to set it up once, and it will work every day without any intervention. You won't even need to think about content or scheduling. I have tried to make this blog beginner-friendly and easy to understand, and I hope it will help you.

1. ### Getting X / Twitter API Keys
    

**Step 1:** Visit [Twitter Developer](https://developer.x.com/).  
**Step 2:** Click on the "Developer Portal".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716643452137/638866b6-04e9-4430-a84e-7d8dc5205e4a.png align="center")

**Step 3:** You will need to sign in to your X account using credentials (if not already signed in to X), If you have never used Twitter Developer Portal then you will need to fill out a form mentioning basic details such as your country, name, how will you use Twitter API (this is important, fill it carefully), etc and it will get approved in 24 hours.

![app in twitter developer account](https://elfsight.com/wp-content/uploads/2020/03/blog-twitter-api-5.jpg align="left")

**Step 4:** Once you’ve set up the account, you can create the app. Navigate to "Projects and Apps" and under Overview apps click on "Create App".

![](https://docs.themeum.com/wp-content/uploads/2023/04/3-tutorlms-social-login-twitter-developer-portal-overview-1024x581.jpg align="left")

**Step 5:** Next name your app. Then click Next. Through this tab, you will find the API Key and the API Secret Key but you don't need to copy it now.  
**Step 6:** Go to the Project you just created (you can see the project name in the left side drawer) and click on the "Edit" option.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716644604676/012513f6-290b-4ad5-8e87-12f97056e3ef.png align="center")

**Step 7:** Make changes as shown in the screenshot below and click on "save".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716644756871/a13cd65a-76cc-465b-b4f4-0dc1e0763a6c.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716644854655/46491abc-2466-4e6a-a8ac-879cff4c4a9c.png align="center")

**Step 8:** Go to "Keys and Tokens" and click on Regenerate in "API Key and Secret" section then copy and save the shown key and secret, and repeat the same with the "Access Token and Secret" section. (we will use it later)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716645036916/a0a3132d-9876-42ad-9c6d-f000de4614d5.png align="center")

2. ### Getting Gemini AI API Key
    

Getting Gemini AI API is pretty simple.  
**Step 1:** Log in to the [Google AI Studio](https://makersuite.google.com/app/apikey) for the Gemini AI and click "Get API Key".

![Use the Log in or Sign up button](https://www.geminiforwork.com/assets/images/google-ai-studio-181a378a022ae9a1e2664b9da67f1462.png align="left")

**Step 2:** Click "Create API key in new project".

![In the API Keys window, use the Create API key in new project](https://www.geminiforwork.com/assets/images/create-api-key-d030abd730f9129cd30fd29cfbcce6b7.png align="left")

**Step 3:** Copy your key to your clipboard and save it somewhere. (we"ll need this later)

![In the API key generated window, use the Copy button](https://www.geminiforwork.com/assets/images/copy-api-key-3ba36c7aca16eab0bb882b634f9bc2ae.png align="left")

3. ### Setting up the code
    

You need to have a GitHub account to automate it.  
**Step 1:** Visit this [Repository](https://github.com/VishwaGauravIn/twitter-auto-poster-bot-ai). ([https://github.com/VishwaGauravIn/twitter-auto-poster-bot-ai](https://github.com/VishwaGauravIn/twitter-auto-poster-bot-ai)) and click on "Fork".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716646009203/48f2ae7d-a8c2-431f-bb9a-7a89d82669a7.png align="center")

**Step 2:** Click on "Create fork".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716646204441/a9951d28-876c-4c7b-a4c5-4db350d30a91.png align="center")

**Step 3:** Click on the "SECRETS.js" file and then click on the pencil icon.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716646754652/ae645be2-74e2-43c4-a4cd-336d5a24e47e.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716646884064/6ec91d31-dfac-4dec-8c94-cd26601758cd.png align="center")

**Step 4:** Click on "Commit changes..." and then a dialogue will open, again click on "Commit Changes"

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716647138209/65c8d889-cc59-4000-a74d-0fb9c5045f2b.png align="center")

**Step 5:** Click on the repository name as shown in the screenshot below, select "I understand my workflows, go ahead and enable them". Click on "Auto Tweet using AI".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716647375481/c968ae94-235d-45a8-9efd-31bb4bf5ba39.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716647425499/93efaff6-02cf-4fde-9a7c-0f8476ced223.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716647552851/14f52ae7-530f-42a4-9e09-d3daa9e272b0.png align="center")

**Final Step:** Click "Enable workflow" and then "Run Workflow".

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716647664959/c7e395fc-2a92-47db-b7f8-50e8fe0931b8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716647714801/203b649a-becb-4dd1-9af4-37ef4561be86.png align="center")

**Bonus:** You can customize the prompt in the "index.js" file to generate different types of tweets. (by default it generates tips and tricks for web development)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1716649905883/e1b755d1-7f49-408b-accd-8e872dd32f31.png align="center")

![Minions Well Done Congratulations GIF | GIFDB.com](https://gifdb.com/images/high/well-done-congratulations-498-x-224-gif-ga95en2db9gfkr53.gif align="left")

**Congratulations 🎉**, now you have completely automated your Twitter account using AI, now sit back and enjoy!

Thanks for reading this long blog 💛  
You can follow me on [Twitter / X](https://twitter.com/vishwagauravin) | [LinkedIn](https://www.linkedin.com/in/vishwagauravin/) | [GitHub](https://github.com/VishwaGauravIn)

> <mark>Note:</mark> I have tested this with multiple accounts for more than 3 months and none of my accounts faced any issue or ban, but I highly reccommend you to first try it on your secondary or dummy acccount as no one knows what elon will change next. 😂  
> It is advisable to use environment variables instead of directly putting secrets in repository file but I have skipped this part as it would become complicated for many. Alternatively you can download the repository instead or forking and upload it from your account and keep it private, in that way, your secrets will not be exposed to the public.
