开发者

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 red开发者_StackOverflowirected 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.


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=", "");


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜