0

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 if 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

2 Answers2

3

You should be able to do something like String code = req.getParameter("code");

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
1

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){
////
} 
danny.lesnik
  • 18,479
  • 29
  • 135
  • 200
  • Of course, it works. The call of [WEB_PAGE] by Facebook contains a bunch of parameters, including a **data** parameter, which is passed unchanged from the call made by the application. – Alexis Dufrenoy Nov 13 '10 at 23:54