saurav
saurav

Reputation: 5946

Facebook Graph API not redirecting

I am new to Facebook APIs. I am stuck at a very basic stage. Below is my problem.

I have registered my application with Facebook.

I get the code parameter by authorizing the user with the Facebook from my web site by using an url.

From that I properly get the code and get redirected to the facebookjsp.jsp

But now when I try to fetch the access token with this url

https://graph.facebook.com/oauth/access_token?
    client_id=" "&
    redirect_uri=http://localhost:8080/project_fb/facebookjsp.jsp&
    client_secret=" "&
    code=" "

I am not redirected to the facebookjsp.jsp instead it goes to the graph.facebook.com and shows me the access token.

I might be missing something here as i am new to Graph API.

Upvotes: 1

Views: 1160

Answers (2)

saurav
saurav

Reputation: 5946

In case if anyone bumps up to this thread here is I how you can parse the response in your jsp.

<%!
    private String readUrl(String urlString) throws IOException {
        URL url = new URL(urlString);       BufferedReader in = new BufferedReader(new InputStreamReader(url
            .openStream()));

        String response = "";
        String inputLine;

        while ((inputLine = in.readLine()) != null)
           response += inputLine;

        in.close();

        return response;
    }
%>

Take the access token and split it

accessToken=readUrl(accessTokenURLStr).split("&")[0].replaceFirst("access_token=", "");

Upvotes: 1

Hurda
Hurda

Reputation: 4715

This is standard behaviour - you must call this page from your server and parse the response. The redirect parameter is just some type of security/annoyance/legacy stuff - you need to put same URL as you did with the authorization.

Upvotes: 0

Related Questions