1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[URL/COOKIE help] Facebook URL's for login / to request

Discussion in 'General Programming Chat' started by teqqy, Jun 16, 2010.

  1. teqqy

    teqqy Newbie

    Joined:
    Jun 12, 2010
    Messages:
    45
    Likes Received:
    199
    Hello there, I don't know if this is the right section or not, but it does deal with programming. I'm trying to make a bot IN JAVA ( :p) to login to facebook, and then grab the number of friends. Grabbing the friends is not what I'm worried about, as I am having trouble with getting it to login correctly. I don't know how to request a page to submit the details to.

    What I have so far on this subject is:

    Code:
    https://login.facebook.com/login.php?email=kdfnkdjf&password=30434
    But all this does is fill in the username, and depending on the page
    This is the same with facebook.com.login.php?


    From a programmatic standpoint, I have this as my java code:

    Code:
    import java.net.*;
    import java.io.*;
    
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author TeQQy
     */
    
    
    public class Main {
     public static void main(String[] args) {
     tryLogin();
        }
    
    static void tryLogin(){
      try{
    
    URL url = new URL("http://www.facebook.com/login.php");
    
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("GET");
    connection.setInstanceFollowRedirects( true );
    connection.setDoOutput( true );
    connection.setDoInput( true );
    connection.setUseCaches( true );
    connection.setRequestProperty( "Content-Type","application/x-www-form-urlencoded" );
    System.out.println( "Response: " + connection.getResponseMessage() );
    
    ///////////////////////
    //read buffer
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    connection.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);
    in.close();
    //
    /////////////////////
    System.out.println("");
    int j = 0;
    
    while( connection.getHeaderField(j) != null )
    
    {
    
    System.out.println("Header " + j + ": " + connection.getHeaderField(j) );
    
    j++;
    
    }
    
    System.out.println("URL: " + connection.getURL().toString() );
    
    String cookie = connection.getHeaderField("set-cookie");
    
    String firstcookie = "";
    
    System.out.println("Cookie: " + cookie);
    url = new URL("http://www.facebook.com/login.php");
    connection = (HttpURLConnection)url.openConnection();
    connection.setUseCaches( true );
    connection.setRequestMethod("POST");
    connection.setDoOutput( true );
    connection.setDoInput( true );
    
    connection.setFollowRedirects( true );
    
    System.out.println("Cookies Test: " + firstcookie);
    
    connection.setRequestProperty( "Content-Type","application/x-www-form-urlencoded" );
    
    connection.setRequestProperty("Cookie", firstcookie);
    
    System.out.println( "Response: " + connection.getResponseMessage() );
    
    in = new BufferedReader(
    
    new InputStreamReader(
    
    connection.getInputStream()));
    
    while ((inputLine = in.readLine()) != null)
    
    System.out.println(inputLine);
    
    j = 0;
    
    while( connection.getHeaderField(j) != null )
    
    {
    
    System.out.println("Header " + j + ": " + connection.getHeaderField(j) );
    
    j++;
    
    }
    
    System.out.println("\nURL: " + connection.getURL().toString() );
    
    System.out.println( "Response: " + connection.getResponseMessage() );
        }
    
    
    
      catch( java.io.IOException s){
    
          }
        }
    
    
    
    
    }
    The output is :
    Code:
    Header 0: HTTP/1.1 200 OK
    Header 1: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Header 2: Sat, 01 Jan 2000 00:00:00 GMT
    Header 3: CP="DSP LAW"
    Header 4: no-cache
    Header 5: datr=1276642830-badc4152bcba9f9077f2dbd0ac58c846c3ece110ca1a195e1b1c4; expires=Thu, 14-Jun-2012 23:00:30 GMT; path=/; domain=.facebook.com
    Header 6: lsd=cGxwa; path=/; domain=.facebook.com
    Header 7: reg_fb_gate=http%3A%2F%2Fwww.facebook.com%2Flogin.php; path=/; domain=.facebook.com
    Header 8: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Flogin.php; path=/; domain=.facebook.com
    Header 9: text/html; charset=utf-8
    Header 10: close
    Header 11: Tue, 15 Jun 2010 23:00:30 GMT
    Header 12: 12503
    URL: http://www.facebook.com/login.php
    Cookie: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Flogin.php; path=/; domain=.facebook.com
    Cookies Test: 
    Response: Bad Request
    I don't know why I am getting a Bad Request.



    This brings me to my next issue. What am I supposed to use for cookies?

    Do I just use:
    Code:
    Cookie: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Flogin.php
    Becuase, I feel like I need to use:
    Code:
    Set-Cookie: datr=1263606883-353220e34df7c8240bc7e9900cee2b87258e47ea29087c5b59f41; expires=Thu, 14-Jun-2012 23:17:10 GMT; path=/; domain=.facebook.com
    Set-Cookie: reg_fb_ref=https%3A%2F%2Flogin.facebook.com%2Flogin.php%3Femail%3Dkdfnkdjf%26password%3D30434; path=/; domain=.facebook.com
    
    But I dont think those exact values are returned, but you get the point.

    Anyway, any help I can get on this project will be greatly appreciated :)


    If it's more convenient to speak over MSN add me @ promise_skating@hotmail.com


    Thanks, and I hope to hear from someone who knows what they are doing.

    PS)If anyone has any example of this in any .NET please share :)