I am currently working on an application that extracts data from Twitter profiles. I want to give the user the ability to select which parts of their profile should be used (for example, excluding tweets). To accomplish this, I plan to incorporate checkboxes for users to designate specific preferences. Upon clicking the login button, my intention is to utilize Javascript to identify the selected checkboxes and then initiate an AJAX call to trigger the Java function responsible for initiating the Twitter login process. However, before proceeding with this implementation, I want to ensure that the function performs as expected. The issue I am encountering is that the redirect command in the function does not appear to be functioning correctly. Despite verifying the successful execution of all other lines in the function, including testing with a sample file, the redirect command fails to direct the user to the Twitter login page. Any insights or suggestions would be greatly appreciated. Please see the code below:
Javascript
<input id="tw" type="button" onclick="twitterLogin()"value="Login to Twitter"/>
function twitterLogin(){
$.ajax({
type: "POST",
url: "@{Application.requestToken()}",
data: {
text: "Well that's odd"
}
})
}
Java
public static void requestToken(String text){
try{
String prelimOAuthToken = Twitter.getRequestToken();
if(prelimOAuthToken.equals("Failed")){
FileWriter fstream = new FileWriter("Error log.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Getting a request token failed");
out.close();
}
else{
BufferedWriter b = new BufferedWriter(new FileWriter("Output.txt"));
b.write(text);
b.close();
//Now we use this oauth token to redirect the user for authentication
String url = "https://api.twitter.com/oauth/authenticate?oauth_token=" + prelimOAuthToken;
redirect(url);
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}