Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

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!
[295 byte] By [Sportsdude11751] at [2007-11-11 8:16:19]
# 1 Re: i need help please!
Are you thinking java script? Are you writting a script to be run in a browser or a java program to be compiled? I don't mean to insult really I don't.
hexaplus at 2007-11-11 22:36:01 >
# 2 Re: i need help please!
take a look at httpclient from apache (use google)

once there look under methods to the left and then look at post.
anubis at 2007-11-11 22:36:55 >
# 3 Re: i need help please!
i've tried looking at the html code but i can't quite figure it out, you guys wouldnt know how you could do it would you? like some quick code would be nice
Sportsdude11751 at 2007-11-11 22:37:54 >
# 4 Re: i need help please!
ok i'll give it a shot...might take a while lol
anubis at 2007-11-11 22:38:59 >
# 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 >
# 6 Re: i need help please!
hey thanks for the code, I downloaded the apache folder and put it in my file where i save my java work to but it can't find from it so what folder do i need to put in?
Sportsdude11751 at 2007-11-11 22:41:07 >
# 7 Re: i need help please!
are you using some kind of compiler software?
anubis at 2007-11-11 22:42:00 >
# 8 Re: i need help please!
If by apache "folder" you mean a jar file, just throw it in your extensions folder of where you have the jsdk installed.
Phaelax at 2007-11-11 22:43:03 >
# 9 Re: i need help please!
yes, i'm using JCreator. i didn't find any jar folder though. Maybe I downloaded the wrong folder, but I don't think so?What was the download link you guys used?
Sportsdude11751 at 2007-11-11 22:44:06 >
# 10 Re: i need help please!
ok cool i use jcreator as well...i'll put the links for the files you need...one sec

here they are:
just unzip the files and then have jcreator use the jar files inside the unzipped folders

http://apache.mirror99.com/jakarta/commons/httpclient/binary/commons-httpclient-3.0.zip
http://apache.mirrors.versehost.com/jakarta/commons/codec/binaries/commons-codec-1.3.zip
http://www.ip97.com/apache.org/jakarta/commons/logging/binaries/commons-logging-1.0.4.zip

im not sure when you need the logging file, but here it is anyway
anubis at 2007-11-11 22:45:07 >
# 11 Re: i need help please!
i've extracted the folders to the extensions and it still says it can't find the package.
-------Configuration: <Default>-------
C:\Java\MySpace.java:1: package org.apache.commons.httpclient does not exist
import org.apache.commons.httpclient.*;
^
C:\Java\MySpace.java:2: package org.apache.commons.httpclient.methods does not exist
import org.apache.commons.httpclient.methods.*;
Sportsdude11751 at 2007-11-11 22:46:10 >
# 12 Re: i need help please!
did you make sure to tell JCreator that you want to include those .jar files when you compile?

Configure -> Options -> JDK Profile -> (should be one listed) Select it and click Edit -> then add archive -> add each of the .jar files.
anubis at 2007-11-11 22:47:13 >
# 13 Re: i need help please!
ok freak out time.
I just signed up to this site about the same thing.

I have a program that signs into myspace.

I was going to ask for help on fine tuning it.

If anyone is intrested in working with me please let me know.

I am looking for a team to help develop something really cool.

sprnch@gmail.com

As for the guy that asked I guess I can give you the sign in part.
sprnch at 2007-11-11 22:48:09 >
# 14 Re: i need help please!
yeah that sounds cool, I'm at school now so i cant email, after this week my research paper will be done so i'll have lots of time left over, my aim is Sportsdude11751 and email kevin_western25@yahoo.com
Sportsdude11751 at 2007-11-11 22:49:09 >