Bonjour à tous.

je sais qu'à partir de facebook on accède aux données basiques de n'importe quel utilisateur via son id avec cet url :

En théorie, on n'a pas besoin de s'authentifier pour y accéder puisque ça marche pour n'importe quel user.

Mais lorsque je fais ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
JSONObject resp = new JSONObject( IOUtil.urlToString(new URL("https://graph.facebook.com/"+id_user)));
 
String firstName = resp.getString("first_name");
...
j'ai une erreur failed login, connection reset by peer.

j'ai trouvé à ce lien une classe pour s'authentifier :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class FBOAuth implements Filter {
 
    public void init(FilterConfig fc) throws ServletException {
    }
 
    public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)sr;
        HttpServletResponse res = (HttpServletResponse)sr1;
        String code = sr.getParameter("code");
        if (StringUtil.isNotBlankStr(code)) {
            String authURL = Facebook.getAuthURL(code);
            URL url = new URL(authURL);
            try {
                String result = readURL(url);
                String accessToken = null;
                Integer expires = null;
                String[] pairs = result.split("&");
                for (String pair : pairs) {
                    String[] kv = pair.split("=");
                    if (kv.length != 2) {
                        throw new RuntimeException("Unexpected auth response");
                    } else {
                        if (kv[0].equals("access_token")) {
                            accessToken = kv[1];
                        }
                        if (kv[0].equals("expires")) {
                            expires = Integer.valueOf(kv[1]);
                        }
                    }
                }
                if (accessToken != null && expires != null) {
                    UserService us =[COLOR="Red"] UserService.get();
                    us.authFacebookLogin(accessToken, expires);
                    res.sendRedirect("http://www.onmydoorstep.com.au/");
                } else {
                    throw new RuntimeException("Access token and expires not found");
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
 
    private String readURL(URL url) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream is = url.openStream();
        int r;
        while ((r = is.read()) != -1) {
            baos.write(r);
        }
        return new String(baos.toByteArray());
    }
 
    public void destroy() {
    }
}
Je cherche tout tuto là dessus, example, idée, conseil. Merci à vous