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:开发者_C百科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
.
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
精彩评论