Integration with facebook login

Asked

Viewed 56 times

1

I am developing an application and need to login with Facebook

I did some research and I saw that you can do with the 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;
}
  • In which of the calls the problem occurs?

  • in readUrl, exactly on that line Bytearrayoutputstream baos = new Bytearrayoutputstream(); Inputstream is = newUrl.();

  • Have you checked if the variable client_secret this empty?

  • Yes, not empty, I’m assigning value to it just when I declare

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.