How do I access a redirected url from my java servlet?
Hey guys, I've started doing some work on servlets, and I need to implement a facebook login for one of my projects. I created a dummy app on facebook, and I am using restfb for this. First I redirect the user to
https://graph.facebook.com/oauth/authorize?client_id=[MY_APP_ID]&display=page&redirect_uri=[MY_WEBPAGE]&scope=[PERMISSIONS_MY_APP_IS_ASKING_FOR]
to get permission, and i开发者_如何学Cf the user clicks allow, then facebook redirects the user to [MY_WEBPAGE]/?code=XXXX, and I need to be able to have access to whatever comes after code. How would I fetch the part after "code" in a servlet?
Thanks
You should be able to do something like String code = req.getParameter("code");
If I remember correctly, you can't do itn because your [WEB_PAGE] should end with "/" character. What I have done is to map my servlet (let's call facebook) as /facebook/* and then set code as /facebook/XXXX/
After it you can grab this URI and extract your XXXX value and assign it as to code variable.
Hope it Help. If you are using Spring MVC framework then you can do it as
@RequestMapping(value="/facebook/{code}")
public List<Category> facebookapp(@PathVariable String code,Model){
////
}
精彩评论