Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oAuthConfig() {
- var oAuthConfig = UrlFetchApp.addOAuthService("twitter");
- oAuthConfig.setAccessTokenUrl("http://api.twitter.com/oauth/access_token");
- oAuthConfig.setRequestTokenUrl("http://api.twitter.com/oauth/request_token");
- oAuthConfig.setAuthorizationUrl("http://api.twitter.com/oauth/authorize");
- oAuthConfig.setConsumerKey("consumer");
- oAuthConfig.setConsumerSecret("secret");
- }
- function postImage() {
- oAuthConfig();
- var boundary = "cuthere";
- var picture = UrlFetchApp.fetch("http://1cak.com/")
- .getBlob().setContentTypeFromExtension();
- var status = "Tweet text with image upload";
- var requestBody = Utilities.newBlob(
- "--"+boundary+"\r\n"
- + "Content-Disposition: form-data; name=\"status\"\r\n\r\n"
- + status+"\r\n"+"--"+boundary+"\r\n"
- + "Content-Disposition: form-data; name=\"media[]\"; filename=\""+picture.getName()+"\"\r\n"
- + "Content-Type: " + picture.getContentType()+"\r\n\r\n").getBytes();
- requestBody = requestBody.concat(picture.getBytes());
- requestBody = requestBody.concat(Utilities.newBlob("\r\n--"+boundary+"--\r\n").getBytes());
- var options = {
- method: "post",
- contentType: "multipart/form-data; boundary="+boundary,
- oAuthServiceName: "twitter",
- oAuthUseToken: "always",
- payload: requestBody
- };
- var request = UrlFetchApp.fetch("https://api.twitter.com/1.1/statuses/update_with_media.json", options);
- }
Add Comment
Please, Sign In to add comment