S'authentifier à Facebook
Alors j'ai pu trouvé 2 manières pour s'authentifier a un serveur http mais elle ne fonctionne pas.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
private static String downloadPage(URL url){
URLConnection conn = null;
InputStreamReader in;
BufferedReader data;
String line;
StringBuffer buf = new StringBuffer();
try {
conn = url.openConnection();
// HttpURLConnection.setFollowRedirects(true);
String user ="";
String pass ="";
String userpass = user+":"+pass;
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
conn.setRequestProperty ("Authorization", basicAuth);
conn.connect();
in = new InputStreamReader(conn.getInputStream());
data = new BufferedReader(in);
while ((line = data.readLine()) != null){
buf.append(line + "\n");
}
return buf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
} |
j'ai essayé:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
static class MyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
// I haven't checked getRequestingScheme() here, since for NTLM
// and Negotiate, the usrname and password are all the same.
System.err.println("Feeding username and password for " + getRequestingScheme());
return (new PasswordAuthentication(kuser, kpass.toCharArray()));
}
}
public static void main(String args[]) // Le main...
{
Authenticator.setDefault(new MyAuthenticator());
String page = downloadPage(new URL("http://m.facebook.com/#!/unpseudo"));
try{
FileWriter fw = new FileWriter("lapage.txt");
fw.write(p.getData());
fw.close();;
}catch(Exception e){
e.printStackTrace();
}
} |
Ce qu'on voit dans lapage.txt c'est qu'on a le code source de la page tel qu'on la verrait si on n'était pas authentifié a facebook.
En gros ma question c'est comment faire pour etre identifier à facebook ?