Location not populated on Spring Social Facebook

I am trying to find the location of a user in Spring Social Facebook:

Facebook fb = ((Facebook) connection.getApi()); Page pg = fb.pageOperations().getPage(fb.userOperations().getUserProfile().getLocation().getId()); 

The problem is that pg.getLocation() returns null .

I also tried using

 fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class) 

but it fills only the name, not the country or other fields.

Trying to use the Graph API /v2.6/112286918797929? Fields = id, name, location returns as expected:

 { "id": "112286918797929", "name": "Sacele", "location": { "city": "Sacele", "country": "Romania", "latitude": 45.6167, "longitude": 25.6833 } } 

Is this a problem with Spring Social Facebook?

I am using Spring Social 1.1.4 and Spring Social Facebook 2.0.3.

I also tried Spring Social for Facebook - getting the user's location , but, unfortunately, not all places follow the name "City", "Country" and some of them include the name only the city, not the country. Plus, how can you get the geo-coordinates?

+7
java spring-social spring-social-facebook facebook-graph-api
source share
2 answers

I finally understood. This primarily does not work with PageOperations , but it works with GraphApi .

And code

 UserProfile userProfile = fb.userOperations().getUserProfile(); Page pg = fb.fetchObject(userProfile.getLocation().getId(), Page.class, "location"); 

The trick indicates the third parameter that represents the fields (you can specify multiple fields as strings). Now the page is full and you can get the country as pg.getLocation().getCountry() .

+3
source share

As you stated, the following command

 fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class) 

gives the answer to the name that is in the link.

It has 2 public methods: getId() and getName() .

Some methods, such as getLocation() , are permission dependent. If any user gives you permission to view their location, you can access this method.

From the documentation:

getLocation

public Link getLocation ()

User location. Available only with the permissions of "user_location" or "friends_location".

Returns: a Link to the user's location, if available

Code example:

  Page profile=facebookTemplate.pageOperations().getPage(id); String name=profile.getName(); String webside=profile.getWebsite(); String logo="http://graph.facebook.com/" + id + "/picture"; party=new FullPoliticalParty(name,color,logo,webside); String phone=profile.getPhone() == null ? "No disponible" : profile.getPhone(); party.setPhone(phone); org.springframework.social.facebook.api.Location loc=profile.getLocation(); if (loc != null) { location=new LocationMapa(loc.getCity(),loc.getCountry(),loc.getStreet(),loc.getZip()); } party.setLocation(location); 

Link to the resource:



Update1:

I think you need user rights through the Graph API. You can then access the location or other information that you requested from a specific user. Checking Current Permissions and Handling Missing Permissions are given in this link .

For USER user rights:

 /* make the API call */ new GraphRequest( AccessToken.getCurrentAccessToken(), "/{user-id}/permissions", null, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ } } ).executeAsync(); 

For user permissions you can go through this tutorial.

For the user's location, you can go through this tutorial .

Once you get permission, you can also access location, longitude, latitude, and other information.

0
source share

All Articles