xxxxxxxxxx
68
var consumerKey = 'jJKwYVKkqnSkbr63NpK7Vzvkx';
var consumerSecret = 'lTMfwMs7rDxz8vPcxBD7Gy5lDO8GXnlIzPw2d8xVhqa1L4xOTw';
var token = '364475473-kMBumzdzoxKZcduTwFGizG0iyMldRx1CQtcRXm2w';
var tokenSecret = 'KBjBbqUZ0of2SQZDFEqSFof7kQPpENigIh7d3BMUQyCjN';
var cb = new Codebird();
function setup() {
createCanvas(100, 125);
background(255);
noStroke();
fill(150, 0, 100);
rect(width/4, height/4, 50, 50);
//var img = captureImage();
//postImage(img);
}
function captureImage(){
var currentCanvas = document.getElementById("defaultCanvas0");
var b64Img = currentCanvas.toDataURL('image/png').replace(/data:image\/png;base64,/, '');
return b64Img;
}
function postImage(img){
cb.setConsumerKey(consumerKey, consumerSecret);
cb.setToken(token, tokenSecret);
var params = {
"media_data": img
};
cb.__call(
"media_upload",
params,
parseMediaId
);
}
function parseMediaId(reply, rate, err){
let mediaId = reply.media_id_string;
sendTweet(mediaId);
}
function sendTweet(mediaId){
cb.setConsumerKey(consumerKey, consumerSecret);
cb.setToken(token, tokenSecret);
cb.__call(
"statuses_update",
{
"media_ids": mediaId
//"status": "Whohoo, I just tweeted two images!"
},
function (reply, rate, err) {
console.log(reply);
}
);
}
function draw() {
}