Skip to content
This repository was archived by the owner on Sep 15, 2026. It is now read-only.
This repository was archived by the owner on Sep 15, 2026. It is now read-only.

How to post link text / images #185

Open

Description

@pguardiario

Can someone point me to some docs?
I'm trying html, markdown, I'm out of guesses.
Thanks in advance

Activity

  1. charlesr1971 commented on Dec 9, 2021

    @charlesr1971

    Please nudge the authors to approve my PR:

    #187

    This provides proper support for uploading images, using the:

    POST media/upload [v1.1] endpoint

    This can then be combined with the:

    POST statuses/update [v1.1] endpoint

    So that a tweet can be posted, with an image

  2. charlesr1971 commented on Dec 9, 2021

    @charlesr1971

    Once my PR is merged, this is the code you will need:

    async function createNewTwitterClient (subdomain, extension, response, twitterAppConfig, version) {
      const twitter = require(‘twitter-lite’);
      return new twitter({
        subdomain,
        consumer_key: twitterAppConfig.consumerKey, // from Twitter.
        consumer_secret: twitterAppConfig.consumerSecret,
        extension, // true is the default (this must be set to false for v2 endpoints),
        access_token_key: twitterAppConfig.accessTokenKey, // from your User (oauth_token)
        access_token_secret: twitterAppConfig.accessTokenSecret, // from your User (oauth_token_secret)
        bearer_token: response ? response?.access_token : null,
        version
      });
    }
    
    async function shareTwitterCircle(filename, twitterAppConfig, message) {
      const twitterApiClient = await createNewTwitterClient('api', true, null, twitterAppConfig,'1.1');
      const uploadClient = await createNewTwitterClient('upload', false, null, twitterAppConfig,'1.1');
      const uploadResponse = await uploadClient.getBearerToken();
      const twitterUploadClient = await createNewTwitterClient('upload', true, uploadResponse, twitterAppConfig,'1.1');
      const mediaFile = path.join(someDir, filename);
      return new Promise(function (resolve, reject) {
        const base64image = Buffer.from(mediaFile).toString('base64');
        twitterUploadClient.post('media/upload', { media_data: base64image }).then(media => {
          const media_id = media.media_id_string;
          twitterApiClient.post('statuses/update', { status: message, media_ids: media_id }).then(tweet => {
            resolve(tweet);
          }).catch((err)=>{
            reject(err);
          });
        }).catch((err)=>{
          reject(err);
        });
      });
    }
    
    const filename = 'some/file/path',
      twitterAppConfig = {
        consumerKey: ‘CONSUMER_KEY’,
        consumerSecret: ‘CONSUMER_SECRET’,
        accessTokenKey: ‘ACCESS_TOKEN_KEY’,
        accessTokenSecret: ‘ACCESS_TOKEN_SECRET’,
      },
      message = 'Hello World!';
    
    (async function () {
      const tweet = await shareTwitterCircle(filename, twitterAppConfig, message);
    })();
    
    
  3. pguardiario commented on Jul 2, 2022

    @pguardiario
    Author

    It feels like this project is abandoned so I'm looking for another one. Anyone have a suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions