i need help please!
ok so i'm trying to make a program that will log into myspace and preform a search on the settings i select, the problem is you have to be logged in to do this, so I was wondering if any of you guys knew how to pass the information to myspace and login, this would be very helpfull, thanks!
# 5 Re: i need help please!
ok, well here is the code to log into myspace...thats all it does, the rest is for you to figure out lol
if you didnt know, i used httpclient from apache
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import java.net.*;
import java.io.*;
import java.util.StringTokenizer;
public class MySpace
{
public static void main(String [] args)
{
// Declares all the varibales
HttpClient client = new HttpClient();
PostMethod post;
HttpMethod urlMethod = new GetMethod("http://www.myspace.com");
String source = "", tokenURL = "";
String line = "", tempString, url = "";
BufferedReader in = null;
int position;
try
{
// Executes the method that connects to myspace.com
client.executeMethod(urlMethod);
// reads in the reponse that the program gets...basically the source code of the website
in = new BufferedReader(new InputStreamReader(urlMethod.getResponseBodyAsStream()));
// stores that information
while((line = in.readLine()) != null)
source += line;
// Finds the first occurance of 'form action=\"http://login'
position = source.indexOf("form action=\"http://login");
// Since myspace gives a random 'key' to each user, this code gets that key
tempString = source.substring(position + 13, position + 150);
StringTokenizer urlToken = new StringTokenizer(tempString);
url = urlToken.nextToken("\"");
// same thing as above, just gets the key itself
// system.out tokenURL if you want to see it
position = url.indexOf("MyToken");
tokenURL = url.substring(position + 8, url.length());
// creates a new post method
post = new PostMethod(url);
// your log in information
NameValuePair[] loginData = {
new NameValuePair("email", "your email"),
new NameValuePair("password", "your password")
};
// basically logs into the website.
post.setRequestBody(loginData);
client.executeMethod(post);
post.releaseConnection();
// this long url is the redirect url
HttpMethod redirectMethod = new GetMethod("http://home.myspace.com/index.cfm?fuseaction=user&==&setonlinenow=1&Mytoken=" + tokenURL);
client.executeMethod(redirectMethod);
in = new BufferedReader(new InputStreamReader(redirectMethod.getResponseBodyAsStream()));
source = "";
// this is just to make sure that you logged in correctly...just the source of the logged in homepage or w/e
while((line = in.readLine()) != null)
System.out.println(line);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
anubis at 2007-11-11 22:40:03 >
