Vadim Korzun Vadim Korzun - 7 months ago 55
Java Question

how to correctly use search query of Facebook graph API (android)?

I'm trying to run a query to search for locations using search query facebok graf api for android.

If I try to run this query in the Graph API Explorer, I get this result.

But programmatically it is impossible. I try to make so:

new GraphRequest(AccessToken.getCurrentAccessToken(),"/search?q=coffee&type=place&center=37.76,-122.427",null,HttpMethod.GET,new GraphRequest.Callback()
{
public void onCompleted(GraphResponse response)
{
Log.v("HelloFacebook", response.toString());
}
}).executeAsync();
}


i get nothing (param distance must be number)

if I try without distance i get too nothing, but another message (An access token is required to request this resourse and too)

What could be the problem?

Answer

Right syntax for search in Facebook graph API:

GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/search",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("type", "place");
parameters.putString("center", "53,27");
parameters.putString("distance", "30000");
request.setParameters(parameters);
request.executeAsync();