Facebook - obtain location /places ID via location name

你说的曾经没有我的故事 提交于 2019-12-03 05:57:19

问题


I'm able to return a location's details by sending a query via the graph api with the location's ID, however I'm looking to achieve the reverse - effectively find location id by sending a request containing the location name (city, state etc). Is this possible?


回答1:


This is possible under a few different approaches. You can either search using long / lat positions and put the place name into the query. This search will search places only.

Do the following

https://graph.facebook.com/search?q=ritual&type=place&center=37.76,-122.427&distance=1000&access_token=mytoken.

This will return ritual coffee.

Another way is to search through facebook pages using the following https://graph.facebook.com/search?q=ritual%20coffee&type=page&access_token=mytoken

This way is more difficult as you will obviously need to parse the list in more detail.




回答2:


You also can use the place sdk from facebook:

compile group: 'com.facebook.android', name: 'facebook-places', version: '4.30.0' // For latest version, see https://developers.facebook.com/docs/android/

and then:

PlaceSearchRequestParams.Builder builder = new PlaceSearchRequestParams.Builder();

builder.setSearchText("Cafe");
builder.setDistance(1000); // 1,000 meter maximum distance.
builder.setLimit(10);
builder.addField(PlaceFields.ID);

GraphRequest request = PlaceManager.newPlaceSearchRequestForLocation(builder.build());

request.setCallback(new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
        // Handle the response. The returned ID in JSON is the placeId.
    }

request.executeAsync();



回答3:


If I understand your question correctly you can use fql: https://api.facebook.com/method/fql.query?query=QUERY where query should be something like this: select page_id from place where name = ;

Here is a page for your refrence: http://developers.facebook.com/docs/reference/fql/place/



来源:https://stackoverflow.com/questions/5357608/facebook-obtain-location-places-id-via-location-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!