Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Media

Represents twitter Media Attachment, includes twitter message,

param media

Buffer, url to image, base64 string

example

Using url to a image

import { Media } from 'tweets.ts';

const attachment = new Media('https://path.com/to/image.png')
example

Using a Base64 String

import { Media } from 'tweets.ts';

// get a base64 image data somehow, this uses "fs"
const b64Image = fs.readFileSync('path/to/image.png', { encoding: "base64" });
const attachment = new Media(b64Image)
example

Using a Buffer

import { Media } from 'tweets.ts';

const buffer = fs.readFileSync('path/to/image.png');
const attachment = new Media(buffer);
example

Sending a tweet with Media

import { Media, Client } from 'tweets.ts';
// look below for method specific examples
const client = new Client({
authorization: {
consumer_key: 'your Consumer Key',
consumer_secret: 'Consumer Secret',
access_token: 'Your access token',
access_token_secret: 'Your access token secret',
}
});
const buffer = // ...get buffer some how
const attachment = new Media(buffer);
client.tweetMedia(attachment).then(console.log).catch(console.log)

Hierarchy

  • Media

Index

Constructors

constructor

  • new Media(media: string | Buffer): Media

Properties

Private _downloadedMedia

_downloadedMedia: null | string

altText

altText: null | string

mediaType

mediaType: string

method

method: string

rawBuffer

rawBuffer: null | Buffer

rawMedia

rawMedia: string | Buffer

tweetText

tweetText: null | string

Methods

_download

  • _download(): Promise<Buffer>

getBase64

  • getBase64(): Promise<string>

getBinary

  • getBinary(): Promise<string>

setAltText

  • setAltText(altText: string): Media
  • Set the Alt text for this message

    example
    import { Media } from 'tweets.ts'

    const buffer = // ...get a buffer some how
    const attachment = new Media(buffer);
    attachment.setAltText('A Tweet Sent with tweets.js');

    Parameters

    • altText: string

    Returns Media

setMediaType

  • setMediaType(type: string): Media
  • Sets the media type, useful for chunk uploads

    example
    import { Media } from 'tweets.ts'

    const buffer = // ...get a buffer some how
    const attachment = new Media(buffer);

    attachment.setMediaType('image/jpeg');

    Parameters

    • type: string

    Returns Media

setMethod

  • setMethod(method: string): Media
  • Set method on which the client will upload the image to twitter api, normal only supports images (chunk is broken, for now)

    example
    import { Media } from 'tweets.ts'

    const buffer = // ...get a buffer some how
    const attachment = new Media(buffer);
    attachment.setMethod('chunk');

    Parameters

    • method: string

      either chunk or normal

    Returns Media

setTweet

  • setTweet(tweet: string): Media
  • Set the tweet for this message

    example
    import { Media } from 'tweets.ts'

    const buffer = // ...get a buffer some how
    const attachment = new Media(buffer);
    attachment.setTweet('hey this attachment is send from tweet.js');

    Parameters

    • tweet: string

    Returns Media

toJson

  • toJson(): Promise<{ altText: null | string; media: string; mediaType: string; method: string; rawBuffer: Buffer; tweet: null | string }>
  • Get a object representation of the Media class

    Returns Promise<{ altText: null | string; media: string; mediaType: string; method: string; rawBuffer: Buffer; tweet: null | string }>

Generated using TypeDoc