-
-
Save dawsontoth/2eabc31db388144b3abc to your computer and use it in GitHub Desktop.
/** | |
* This is a really simple social app that demonstrates how to post to Twitter using Appcelerator Titanium. | |
* REQUIRED: DOWNLOAD the "social.js" file from http://appc.me/social.js | |
* and SAVE IT in your app's Resources directory. | |
* | |
* Get API access to Twitter here: https://dev.twitter.com/apps | |
* The consumer key and secret will be used later in this app. Make sure you check "Read & Write"! | |
* | |
* The latest version of this file can always be found at http://appc.me/social.sample.js | |
* | |
* Tweet me @dawsontoth with questions. | |
*/ | |
/** | |
* We'll start by making a window with a button... | |
*/ | |
var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); | |
var shareButton = Ti.UI.createButton({ | |
width: 90, bottom: 10, height: 30, | |
title: 'Tweet "Hello, World!"' | |
}); | |
win.add(shareButton); | |
win.open(); | |
/** | |
* Now we include our JavaScript module. There's more info here on how this works: http://appc.me/jsmodules | |
*/ | |
var social = require('social'); | |
var twitter = social.create({ | |
site: 'Twitter', // <-- this example is for Twitter. I'll expand this to other sites in the future. | |
consumerKey: '9U7332KAWsGzdIZDNpWkw', // <--- you'll want to replace this | |
consumerSecret: 'zG0SgCPfxFcwPyVatmYik9tUXMwcMQaKZjj2wOqQeag' // <--- and this with your own keys! | |
}); | |
/** | |
* And when the user clicks on the button, share a message with the world! | |
* Note that this will show the authorization UI, if necessary. | |
*/ | |
shareButton.addEventListener('click', function() { | |
twitter.share({ | |
message: 'Hello, world!', | |
success: function() { | |
alert('Tweeted!'); | |
}, | |
error: function(error) { | |
alert('Oh no! ' + error); | |
} | |
}); | |
}); | |
/** | |
* Finally, here are some other methods you might want to use: | |
*/ | |
/* | |
twitter.isAuthorized(); | |
twitter.authorize(function() { | |
alert('Authorized!'); | |
}); | |
twitter.deauthorize(); | |
*/ |
In social.js, look for this
var supportedSites = {
twitter: {
accessToken: 'https://api.twitter.com/oauth/access_token',
requestToken: 'https://api.twitter.com/oauth/request_token',
authorize: 'https://api.twitter.com/oauth/authorize?',
update: 'https://api.twitter.com/1/statuses/update.json'
}
};
change to
var supportedSites = {
twitter: {
accessToken: 'https://api.twitter.com/oauth/access_token',
requestToken: 'https://api.twitter.com/oauth/request_token',
authorize: 'https://api.twitter.com/oauth/authorize?',
update: 'https://api.twitter.com/1.1/statuses/update.json'
}
};
Also, make sure your app in twitter has read and write permissions. Regenerate token if needed.
I made these changes but still can't get v1.1. working:
//1.1 instead of 1
update: 'https://api.twitter.com/1.1/statuses/update.json'
//in "send"
message.parameters.push(['oauth_version', "1.0"]);
client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
The token is retrieved, but a share post is not validated (error 32).
Can anyone confirm they got this script working for 1.1?
+1
can't get this to work... any suggestions?
var supportedSites = {
twitter: {
accessToken: 'https://api.twitter.com/oauth/access_token',
requestToken: 'https://api.twitter.com/oauth/request_token',
authorize: 'https://api.twitter.com/oauth/authorize?',
update: 'https://api.twitter.com/1.1/statuses/update.json'
}
};
should make it work for api 1.1 for posting
Hey Dawson,
The code had been working great in my app. However, Twitter recently deprecated the REST API v1 and now I get an error message that I should migrate to API v1.1
Could you please point as to how I should correct this?
Thanks!