Integration with facebook login

1

I'm developing an application and need to sign in with Facebook

I researched a bit and saw what to do with Client OAuth 2.0 .

But when I send the url request to return a token I take the following error

  

Server returned HTTP response code: 400 for URL:

And when I played this url in the browser appeared the following

  

{"error": {"message": "client_secret must be passed over HTTPS", "type": "OAuthException", "code": 1}}

My code is this

public void obterUsuarioFacebook(String code)
        throws MalformedURLException, IOException, JSONException {

    String retorno = readURL(new URL(this.getAuthURL(code)));

    String accessToken = null;
    @SuppressWarnings("unused")
    Integer expires = null;
    String[] pairs = retorno.split("&");
    for (String pair : pairs) {
        String[] kv = pair.split("=");
        if (kv.length != 2) {                
            throw new RuntimeException("Resposta auth inesperada.");                
        } else {
            if (kv[0].equals("access_token")) {
                accessToken = kv[1];
            }
            if (kv[0].equals("expires")) {
                expires = Integer.valueOf(kv[1]);
            }
        }
    }

JSONObject resp = new JSONObject(readURL(new URL(
            "https://graph.facebook.com/me?access_token=" + accessToken)));

    UsuarioFacebook usuarioFacebook = new UsuarioFacebook(resp);
    System.out.println(usuarioFacebook.toString());    

private String readURL(URL url) throws IOException {
    URL newUrl = new URL(validarUrl(url));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream is = newUrl.openStream();
    int r;
    while ((r = is.read()) != -1) {
        baos.write(r);
    }
    return new String(baos.toByteArray());    

public String getLoginRedirectURL() {
    return "https://graph.facebook.com/oauth/authorize?client_id="
            + client_id + "&display=page&redirect_uri=" + redirect_uri
            + "&scope=publish_stream,email,publish_actions";
}

public String getAuthURL(String authCode) {
    return "https://graph.facebook.com/oauth/access_token?client_id="
            + client_id + "&redirect_uri=" + redirect_uri
            + "&client_secret=" + client_secret + "&code=" + authCode;
}
    
asked by anonymous 01.06.2015 / 20:50

0 answers