views:

124

answers:

1

I have a problem with redirection, in my work I have to make a connection to a URL that automatically go to another URL at this point it takes the credential (username and password) and redirect to a URL that contains a parameter which need me. How can I take this parameter?

To be precise, I have to do this:

Embed a Web browser with the URL https://graph.facebook.com/oauth/authorize with your client_id and the type set to user_agent. Since your application is embedding a small window, you can trigger a compact "popup" version of the authorization dialog with the display parameter:

graph.facebook.com/oauth/authorize?
    client_id=...&
    redirect_uri=www.facebook.com/connect/login_success.html&
    type=user_agent&
    display=popup

After the user authorizes your application, we redirect the user back to www.facebook.com/connect/login_success.html with the access token in the URL fragment: www.facebook.com/connect/login_success.html#access_token=...&expires_in=... Intercept the redirect above and read the access token out of the URL. Use the access token to fetch data from the Graph API on behalf of the user: graph.facebook.com/me?access_token=....

I need access_token.

A: 

you can use apache http components httpclient to do this, it will automatically follow redirects

HttpClient client=new HttpClient();
GetMethod get=new GetMethod("graph.facebook.com/oauth/authorize?client_id=...&   redirect_uri=www.facebook.com/connect/login_success.html&type=user_agent&display=popup");
int status=client.exectueMethod(get);

Then you will have the information you need in the Location header of the response which you can access by using:

String location=get.getResponseHeader("location").getValue();

and parse the location-header for the url fragment you want.

hope that helped

smeg4brains
I tried your suggestion but it return me the String: [Lorg.apache.commons.httpclient.Header;@409cb0f4What can I do???
Elena
did you forget get getValue()?
smeg4brains