Reputation: 6513
I'm wondering if there is a way when I click on a button to open up a dialog with a predefined message which the user can (i) edit(text field) (ii) cancel out of (button) and (iii) press ok (button) thus tweeting. I'm using the codebird module and titanium with the following link https://gist.github.com/Rogichi/5905010 This enabled me to send a tweet but only with a set text and no ability to edit, press ok or cancel. Also it only works on the first time you run the app on the phone, after that, I have to uninstall and re-install before I can send again. Any help at all would be much appreciated
Upvotes: 0
Views: 1081
Reputation: 36
you will have to create the window with the two buttons and a textarea so the user can compose his own tweet. i managed to do this using the codebird files you mention, all you have to do is edit the setTweet function like this:(everything else stay the same, doing this enables to send as many tweets with out relaunching the app. good luck)
function setTweet(){
var post = Ti.UI.createButton({
title : 'Send',
right: 10,
width: 80,
height: 30,
top: 10
});
var content = Ti.UI.createTextArea({
color: '#888',
font: {fontSize:20, fontWeight:'bold'},
textAlign: 'left',
value: 'compose a tweet',
top: 60,
width: 280, height : 140
});
var floatW = Ti.UI.createWindow({
backgroundColor:'#fff',
borderWidth:8,
borderColor:'#999',
height:200,width:300,
borderRadius:10
});
floatW.add(post);
floatW.add(content);
floatW.open();
post.addEventListener('click', function(e){
var tweet = content.getValue();
cb.__call(
"statuses_update",
{"status": tweet },
function (reply) {
Ti.API.info("Respuesta al publicar: ");// ...
Ti.API.info(reply);// ...
///////////INSPECT OBJECT
function inspeccionar(obj){
var msg = '';
for (var property in obj){
if (typeof obj[property] == 'function')
{
var inicio = obj[property].toString().indexOf('function');
var fin = obj[property].toString().indexOf(')')+1;
var propertyValue=obj[property].toString().substring(inicio,fin);
msg +=(typeof obj[property])+' '+property+' : '+propertyValue+' ;\n';
}
else if (typeof obj[property] == 'unknown')
{
msg += 'unknown '+property+' : unknown ;\n';
}
else
{
msg +=(typeof obj[property])+' '+property+' : '+obj[property]+' ;\n';
}
}
return msg;
}
//Ti.API.info(inspeccionar(reply));
//Ti.API.info(inspeccionar(reply.errors[0]));
//Ti.API.info(reply.httpstatus);
if(reply.httpstatus == 200)
floatW.close();
else
alert(reply.errors);
}
);
});
}
Upvotes: 1
Reputation: 33345
you can use the twitter intent urls in a webview
see this StackOverflow question
Is there a way to launch a Twitter dialog for sending direct messages?
Upvotes: 0
Reputation: 6095
I would just use a module like this one on the marketplace or this code by Dawson Toth.
You will have to make the actual window to send the tweet and edit the message, this should get you started:
// Set up twitter first
var social = require('social');
var twitter = social.create({
site : 'Twitter',
consumerKey : '*****',
consumerSecret : '*****' // <--- and this with your own keys!
});
// Now create your popup window
var win = Ti.UI.createWindow({layout : 'vertical'});
var tweettext = Ti.UI. createTextField({
hintText : 'Enter what you want to tweet...',
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color: '#336699',
height: 60
});
var send = Ti.UI.createButton({title : 'Send', height : 45});
send.addEventListener('click', function(e) {
// Send the tweet with the text fields value
twitter.share({
message : tweettext.value,
success : function() {
alert('Tweeted!');
},
error : function(error) {
alert('You have already shared this school on Twitter.');
}
});
});
// Cancel button closes the window
var cancel = Ti.UI.createButton({title : 'Cancel', height : 45});
cancel.addEventListener('click', function(e) { win.close(); });
// Add all controls and open the window as a modal
win.add(tweettext);
win.add(send);
win.add(cancel);
win.open({modal: true});
That should give you the idea and enough to get started. Havent tested this, you may have to work with it.
Upvotes: 1