Skip to content

Instantly share code, notes, and snippets.

@ejfox
Created June 11, 2017 21:21
Show Gist options
  • Save ejfox/72144da17b62d07ad32a18b69cd0297f to your computer and use it in GitHub Desktop.
Save ejfox/72144da17b62d07ad32a18b69cd0297f to your computer and use it in GitHub Desktop.
T = new Twit(
{
consumer_key: '...'
consumer_secret: '...'
access_token: '...'
access_token_secret: '...'
timeout_ms: 60*1000
}
)
uploadTweet = (status, b64Content) ->
#console.log 'b64Content', b64Content
T.post('media/upload', { media_data: b64Content }, (err, data, response) ->
mediaIdStr = data.media_id_string
console.log 'Uploading media...' + seed + ' Twitter ID: '+mediaIdStr
if !err
console.log 'Twitter id:', mediaIdStr
altText = 'Randomly generated art from seed: '+seed
meta_params = { media_id: mediaIdStr, alt_text: {text: altText} }
T.post('media/metadata/create', meta_params, (err, data, response) ->
if !err
params = {
status: status
media_ids: [mediaIdStr]
}
T.post('statuses/update', params, (err, data, response) -> console.log(data))
else
console.log 'Error: ', err
)
else
console.log 'Error uploading media: ', err
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment