kalyanhadooptraining / facebook-java-api

Automatically exported from code.google.com/p/facebook-java-api
1 stars 0 forks source link

Exception in FacebookXmlRestClient.users_getLoggedInUser() #341

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am new to the facebook-java-api and trying to write my first canvas 
application to print the information of currently logged in user on a simple 
jsp page in canvas. But I get an exception on call to 
FacebookXmlRestClient.users_getLoggedInUser(), which says that "A session key 
is required for calling this method". I am not sure, if I have missed any step 
to create a session key, before I invoke 
FacebookXmlRestClient.users_getLoggedInUser().

What steps will reproduce the problem?
1.  To make things simple, I am using following code in a plain jsp to create 
FacebookXmlRestClient. Also atatched the JSP.

       IFacebookRestClient<Document> userClient = new FacebookXmlRestClient(FB_API_KEY, FB_SECRET_KEY);
       long facebookUserID = facebookUserID = userClient.users_getLoggedInUser();

2. This throws following exception

com.google.code.facebookapi.FacebookException: A session key is required for 
calling this method
    com.google.code.facebookapi.XmlHelper.parseCallResult(XmlHelper.java:152)
    com.google.code.facebookapi.XmlHelper.parseCallResult(XmlHelper.java:108)
    com.google.code.facebookapi.ExtensibleClient.extractLong(ExtensibleClient.java:2078)
    com.google.code.facebookapi.ExtensibleClient.users_getLoggedInUser(ExtensibleClient.java:590)
    com.google.code.facebookapi.SpecificReturnTypeAdapter.users_getLoggedInUser(SpecificReturnTypeAdapter.java:551)
    org.apache.jsp.test_jsp._jspService(test_jsp.java:65)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

What is the expected output? What do you see instead?
I expect to get the user id of currently logged in user, which in this case is 
myself.

What version of the product are you using? On what operating system?
v3.0.2

Please provide any additional information below.

Original issue reported on code.google.com by puri.pra...@gmail.com on 9 Jan 2011 at 6:30

Attachments:

GoogleCodeExporter commented 9 years ago
I also tried to get sessionKey from cookies and create RestClinet using that 
sessionKey. But it throws a different exception on users_getLoggedInUser() call 
in that case, which says "Session key invalid or no longer valid".

Used following code to get sessionKey from cookie and create 
FacebookXmlRestClient using that:

       Cookie cookies[] = request.getCookies();
       String sessionKey = "";
       for(int i=0; i<cookies.length; i++){
           Cookie cookie = cookies[i];
           if("JSESSIONID".equals(cookie.getName()))
               sessionKey = cookie.getValue();
       }
           userClient = new FacebookXmlRestClient(FB_API_KEY, FB_SECRET_KEY, sessionKey);

Original comment by puri.pra...@gmail.com on 9 Jan 2011 at 8:23

GoogleCodeExporter commented 9 years ago
hi all I need to know how to get user status (ie. is he logged in, or logged 
out)?
what calls are needed in my java server to know that?

thanks in advance.

Original comment by bzu.ah...@gmail.com on 9 Jan 2011 at 8:53

GoogleCodeExporter commented 9 years ago
Hello, this is what I have and it seems to work (after applying patch from 
issue 342).  The patch is only for cookie processing.  If you have client side 
authentication and you have a cookie with a name that starts with "fb_"+appid.

  IFacebookRestClient userClient = new FacebookJsonRestClient(apiKey, apiSecret);
  FacebookWebappHelper facebook = new FacebookWebappHelper(req, resp, apiKey,  apiSecret, userClient); 
  //
  if (facebook.isLogin()) {
      Long fbuid = facebook.getUser();
      // Do stuff.
  }

Original comment by edru...@gmail.com on 30 Jun 2011 at 4:33