ritamnrg / facebook-java-api

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

fql_query returns an empty result #287

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.http.*;
import javax.servlet.*;
import org.w3c.dom.Document;

import com.google.code.facebookapi.FacebookException;
import com.google.code.facebookapi.FacebookWebappHelper;
import com.google.code.facebookapi.FacebookXmlRestClient;
import com.google.code.facebookapi.IFacebookRestClient;
import org.json.JSONException;

public class Canvas extends HttpServlet {

         private static final String FACEBOOK_USER_CLIENT = 
"facebook.user.client";
        private String api_key=<API_KEY>;
        private String secret=<SECRET>;

  @Override
        public void doGet (HttpServletRequest req,
                                         HttpServletResponse res)
        throws ServletException, IOException
  {
                        HttpServletRequest request = 
(HttpServletRequest)req;
                        HttpServletResponse response = 
(HttpServletResponse)res;

                        HttpSession session = request.getSession(true);
                        IFacebookRestClient<Document> userClient = 
getUserClient(session);
                        if(userClient == null) {
                          //  logger.debug("User session doesn't have a 
Facebook API client setup yet. Creating one and storing it in the user's 
session.");
                            userClient = new FacebookXmlRestClient(api_key, 
secret);
                            session.setAttribute(FACEBOOK_USER_CLIENT, 
userClient);
                        }
FacebookWebappHelper<Document> facebook = new 
FacebookWebappHelper<Document>(request, response, api_key, secret, 
userClient);
                        String nextPage = request.getRequestURI();
                        nextPage = nextPage.substring(nextPage.indexOf("/", 
1) + 1); //cut out the first /, the context path and the 2nd /
                //      logger.trace(nextPage);
                        boolean redirectOccurred = 
facebook.requireLogin(nextPage);
                        if(redirectOccurred) {
                                return;
                        }
                        redirectOccurred = facebook.requireFrame(nextPage);
                        if(redirectOccurred) {
                                return;
                        }

                        long facebookUserID;
                        try {
                             facebookUserID = 
userClient.users_getLoggedInUser();
                        } catch(FacebookException ex) {

response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error 
while fetching user's facebook ID");
/*                          logger.error("Error while getting cached 
(supplied by request params) value " +
                                             "of the user's facebook ID or 
while fetching it from the Facebook service " +
                                             "if the cached value was not 
present for some reason. Cached value = {}", 
userClient.getCacheUserId());*/
                            return;
                        }
                          PrintWriter out = res.getWriter();
            String query = "Select name from user where uid=" + 
facebookUserID;
            Document fqlDocument=null;
            try {
            fqlDocument = userClient.fql_query(query);
            } catch (FacebookException e) {
                out.println("error");
            }
        out.println("Hello, Brave new World: " + facebookUserID + " " +  
fqlDocument);
        out.close();

  }
  public static FacebookXmlRestClient getUserClient(HttpSession session) {
            return 
(FacebookXmlRestClient)session.getAttribute(FACEBOOK_USER_CLIENT);
        }

}

What is the expected output? What do you see instead?

to see my facebood uid and name

What version of the product are you using? On what operating system?
using latest version of the product (3.0.2), tested both on Apple Snow 64 
bit and on Linux Gentoo 64 bit and i got the same result.

what am i missing? i did get my facebook user id properly, why can't i run 
any fql queries and why don't i get any results ?

is there any other way to fetch information and profile picture from the 
user?

i used an example to create this peace of code. is the newer version of the 
api supports a different approach? thanks!

Original issue reported on code.google.com by kfirufk@gmail.com on 1 Feb 2010 at 4:35