Pin based authentication in Twitter Titanium

Posted By : Nitin Bhatt | 08-May-2015

In this example i have discussed PIN based authentication issue , which I have faced while sharing message on Twitter.

 

In some devices while sharing a message on Twitter it will ask for 'Enter this PIN to complete the authorization process' , To resolve this issue i have created textField to get pin when user enter it.

 

Write this code in your 'social.js'  inside 'authorizeUICallback' function.

 

var pinField = Ti.UI.createTextField({

width : '85%',

height : 40,

bottom : "5%",

backgroundImage : "screenBackground.png",

borderColor : "#52D3FE",

borderWidth : 3,

hintText : "Enter PIN",

font : {

fontSize : '14sp',

},

keyboardType : Titanium.UI.KEYBOARD_NUMBER_PAD,

returnKeyType : Ti.UI.RETURNKEY_DONE,

color : 'black'

});



view.add(pinField);

pinField.addEventListener("return", function() {

if (!pinField.value) {

aler("Please Enter PIN");

} else {

var response = 1;

pin = pinField.value;

destroyAuthorizeUI();

receivePinCallback();

loading = !1, clearInterval(intervalID), estimates[estimateID] = (new Date).getTime() - startTime, Ti.App.Properties.setString("Social-LoadingEstimates", JSON.stringify(estimates));

}

});
 

 

Write this code in your 'app.js'.

var window = Ti.UI.createWindow({

backgroundImage : "screenBackground.png",

});



var social = require('social');

var twitter = social.create({

site : 'Twitter',

consumerKey : '**', // ---Relace this with your consumer Key

consumerSecret : '**' // ----Replace this with your consumerSecret 

});



var view = Ti.UI.createView({

top : 10,

backgroundColor : '#52D3FE',

height : 40

});

window.add(view);



var label = Ti.UI.createLabel({

text : 'Share On Twitter',

color : 'white',

font : {

fontSize : "18sp",

}

});



view.add(label);



var shareButton = Ti.UI.createButton({

title : 'Share On Twitter',

top : 180,

borderRadius : 6,

backgroundColor : '#52D3FE',

color : 'white',

});



shareButton.addEventListener('click', function(e) {

twitter.share({

message : 'Hello, world from Titaniums!',

success : function() {

alert('you have successfully Tweeted on Twitter');

},

error : function(error) {

alert('Error occuered while sharing on Twitter ');

}

});

});



window.add(shareButton);



window.open();


 

 

 

About Author

Author Image
Nitin Bhatt

Nitin is an Assistant Project Manager specializing in iOS Application Development. He is an avid reader.

Request for Proposal

Name is required

Comment is required

Sending message..