This application uses a Twitter API to post randomized quotes from Gandalf as per Tolkien-related material via The One API (Lord of the Rings-themed API)
- 💍 Technologies Used🌋
- 💍 Description🌋
- 💍 Setup & installation🌋
- 💍 Known-bugs🌋
- 💍 License🌋
- MS EF Core v 6.0.0
- MS EF Core Design v 6.0.0
- C#/.NET
- ASP Core MVC
- Newtonsoft.Json v 13.0.2
- RestSharp v 108.0.3
- TweetinviAPI v 5.0.4
- The One API
- Twitter API v 2.0
This is a Twitter Bot using C#/.NET MS EF Core framework that will post randomized quotes by the character Gandalf from the Lord of the Rings trilogy. Once initiated via the command dotnet run
the bot will tweet a Gandalf quote immediately and then again every 60 minutes until the program is closed.
You can view the tweets @Gandalf_bot.
-
- Clone "The_One_API.Solution" from the repository to your desktop.
-
- Open your terminal (e.g. Terminal or GitBash) and navigate to this project's directory called "The_One_API".
-
- Set up the project:
- Create a file in the production directory "The_One_API" called "EnvironmentVariables.cs"
- Add the following code to the "EnvironmentVariables.cs" file:
namespace The_One_API { public static class EnvironmentVariables { public static string TheOneApiKey = "[YOUR-ONE-API-KEY]"; public static string GandalfCharId = "5cd99d4bde30eff6ebccfea0"; public static string consumerKey = "[YOUR-TWITTER-API-CONSUMER-KEY]"; public static string consumerSecret = "[YOUR-TWITTER-API-CONSUMER-SECRET]"; public static string accessToken = "[YOUR-TWITTER-ACCESS-TOKEN]"; public static string accessSecret = "[YOUR-TWITTER-ACCESS-SECRET]"; } }
- Replace all information in each of the square brackets with your one API key, your twitter api consumer key, your twitter api consumer secret, your twitter access token, and your twitter access secret.
-
- Setting up the necessary accounts:
- Create an account on "The One API" via this link
- Navigate to the webpage and click the 3 horizontal bars on the top right of the screen
- Select "sign up" and provide your email and password
- Copy the given "Access token" and paste to the EnvironmentVariables.cs file in the [YOUR-ONE-API-KEY] section
- Create a Twitter Developer account via this link
- Navigate to the top right of the page and select "Developer Portal"
- Click "sign up" and fill out the necessary fields
- Navigate to the developer portal via this link
- On the main page (dashboard), select the key icon under "project app"
- Click "regenerate" to reveal your twitter API key and API key secret
- Copy each of these and paste them in their respective locations within the "EnvironmentVariables.cs" file: [YOUR-TWITTER-API-CONSUMER-KEY] = API key [YOUR-TWITTER-API-CONSUMER-SECRET] = API key secret
- Within the Developer Portal Settings Tab click the "edit" button under the User Authentication Settings section. Within the User Authentication settings page select the option for Read and Write, Web App, and enter https://twitter.com/ in the Callback URLs field. Click save. The Twitter Access Tokens you will generate in the next step are now enabled with Read and Write permissions.
- Click "generate" to reveal your twitter access token and secret
- Copy each of these and paste them in their respective locations within the "EnvironmentVariables.cs" file [YOUR-TWITTER-ACCESS-TOKEN] = access token [YOUR-TWITTER-ACCESS-SECRET] = access secret
- IMPORTANT NOTE: The client will post tweets from the Twitter account used to sign up for the developer access tokens. If you wish to use Twitter's API to post from other accounts, you will have to follow the additional steps provided here to set up OAuth 2.0 with a Bearer Token.
-
- Within the production directory
\The_One_API
run\$ dotnet watch run
in the command line to build, restore and run application and producd a random Gandalf quote tweet.
- Within the production directory
-
- Program will continue to run and post a tweet every [hour] until manually exited or limit of API calls per month is reached.
- Twitter's API prevents duplicate tweets within a specific timeframe. Duplicate tweets result in a program error with status code 403.
- Twitter limits posts to a maximum of 280 characters. If the randomized movie quote is beyond this limit, our code currently trims the text and adds an ellipses at the end before posting.
- The current free version of Twitter API limits the amount of hourly and monthly requests. Visit https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api for more information. Requests in excess of your allotment return a Code 429.
Please reach out to any of us for questions, comments, or concerns: [email protected], [email protected], [email protected], [email protected], [email protected]