Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twitter post for the new Ratchakitcha #35

Open
ntsd opened this issue Mar 11, 2023 · 1 comment
Open

Twitter post for the new Ratchakitcha #35

ntsd opened this issue Mar 11, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@ntsd
Copy link
Collaborator

ntsd commented Mar 11, 2023

Just an idea, we can create a Twitter user to post when we found a new Ratchakitcha from the sheet.

From this line, I created a log when we found a new doc from the downloaded sheet.

console.log(`found a new document ${row}`)

The unique is generated by hashing all the columns of the row.

@ntsd ntsd added the enhancement New feature or request label Mar 11, 2023
@ntsd
Copy link
Collaborator Author

ntsd commented Mar 17, 2023

From ChatGPT

To post a tweet using Node.js, you can use the twitter-api-v2 npm package. First, you'll need to create a Twitter Developer account, create an app, and obtain the necessary API keys and access tokens.

Here's a step-by-step guide:

Create a Twitter Developer account and an app:

Go to https://developer.twitter.com/ and sign in or sign up for a Twitter Developer account.
After your account is approved, go to the "Dashboard" and click "Create an App."
Fill in the required details and create your app.
Get your API keys and access tokens:

Go to the "Keys and Tokens" tab of your app and note the "API key" and "API key secret."
Generate your "Access token" and "Access token secret" if not already available.
Install the twitter-api-v2 npm package:

Run the following command in your terminal: npm install twitter-api-v2
Create a Node.js script to post a tweet:

javascript
Copy code
// Import the Twitter API client
const { TwitterApi } = require('twitter-api-v2');

// Replace these placeholders with your own API keys and access tokens
const apiKey = 'YOUR_API_KEY';
const apiSecret = 'YOUR_API_SECRET';
const accessToken = 'YOUR_ACCESS_TOKEN';
const accessTokenSecret = 'YOUR_ACCESS_TOKEN_SECRET';

// Initialize the Twitter API client
const twitterClient = new TwitterApi({
  appKey: apiKey,
  appSecret: apiSecret,
  accessToken: accessToken,
  accessSecret: accessTokenSecret,
});

// Function to post a tweet
async function postTweet(status) {
  try {
    const response = await twitterClient.v1.tweet(status);
    console.log('Tweet posted successfully:', response);
  } catch (error) {
    console.error('Error posting tweet:', error);
  }
}

// Post a tweet
postTweet('Hello, Twitter! This is a tweet from my Node.js app!');
Replace the placeholders in the script (YOUR_API_KEY, YOUR_API_SECRET, YOUR_ACCESS_TOKEN, and YOUR_ACCESS_TOKEN_SECRET) with your actual API keys and access tokens.

When you run this script, it will post a tweet with the given message ("Hello, Twitter! This is a tweet from my Node.js app!"). Customize the message as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant