Comments (1)
I resolved the issue by accessing only basic fields (id and name) that needed for creating facebook connection.
@@ -23,19 +23,35 @@ import org.springframework.social.MissingAuthorizationException;
public interface UserOperations {
/**
- * Retrieves the profile for the authenticated user.
+ * Retrieves the basic profile for the authenticated user.
* @return the user's profile information.
* @throws ApiException if there is an error while communicating with Facebook.
* @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
*/
- FacebookProfile getUserProfile();
+ FacebookProfile getBasicProfile();
/**
- * Retrieves the profile for the specified user.
+ * Retrieves the basic profile for the specified user.
+ * @param userId the Facebook user ID to retrieve profile data for.
+ * @return the user's profile information.
+ * @throws ApiException if there is an error while communicating with Facebook.
+ */
+ FacebookProfile getBasicProfile(String userId);
+
+ /**
+ * Retrieves the full profile for the authenticated user.
+ * @return the user's profile information.
+ * @throws ApiException if there is an error while communicating with Facebook.
+ * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
+ */
+ FacebookProfile getUserProfile();
+
+ /**
+ * Retrieves the full profile for the specified user.
* @param userId the Facebook user ID to retrieve profile data for.
* @return the user's profile information.
* @throws ApiException if there is an error while communicating with Facebook.
*/
FacebookProfile getUserProfile(String userId);
@@ -88,12 +104,16 @@ public interface UserOperations {
* @return a list of {@link Reference}s, each representing a user who matched the given query.
* @throws ApiException if there is an error while communicating with Facebook.
* @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
*/
PagedList<Reference> search(String query);
-
- static final String[] PROFILE_FIELDS = {
+
+ static final String[] BASIC_PROFILE_FIELDS = {
+ "id", "about", "link", "name"
+ };
+
+ static final String[] PROFILE_FIELDS = {
"id", "about", "age_range", "bio", "birthday", "context", "cover", "currency", "devices", "education", "email",
"favorite_athletes", "favorite_teams", "first_name", "gender", "hometown", "inspirational_people", "installed",
"is_verified", "languages", "last_name", "link", "locale", "location", "middle_name", "name", "name_format",
"political", "quotes", "relationship_status", "religion", "significant_other", "timezone", "third_party_id",
"verified", "website", "work"
@@ -41,19 +41,28 @@ class UserTemplate extends AbstractFacebookOperations implements UserOperations
super(isAuthorizedForUser);
this.graphApi = graphApi;
this.restTemplate = restTemplate;
}
- public FacebookProfile getUserProfile() {
+ public FacebookProfile getBasicProfile() {
+ requireAuthorization();
+ return getBasicProfile("me");
+ }
+
+ public FacebookProfile getBasicProfile(String facebookId) {
+ return graphApi.fetchObject(facebookId, FacebookProfile.class, BASIC_PROFILE_FIELDS);
+ }
+
+ public FacebookProfile getUserProfile() {
requireAuthorization();
return getUserProfile("me");
}
public FacebookProfile getUserProfile(String facebookId) {
return graphApi.fetchObject(facebookId, FacebookProfile.class, PROFILE_FIELDS);
}
-
+
public byte[] getUserProfileImage() {
requireAuthorization();
return getUserProfileImage("me", ImageType.NORMAL);
}
@@ -29,19 +29,19 @@ import org.springframework.social.facebook.api.FacebookProfile;
*/
public class FacebookAdapter implements ApiAdapter<Facebook> {
public boolean test(Facebook facebook) {
try {
- facebook.userOperations().getUserProfile();
+ facebook.userOperations().getBasicProfile();
return true;
} catch (ApiException e) {
return false;
}
}
public void setConnectionValues(Facebook facebook, ConnectionValues values) {
- FacebookProfile profile = facebook.userOperations().getUserProfile();
+ FacebookProfile profile = facebook.userOperations().getBasicProfile();
values.setProviderUserId(profile.getId());
values.setDisplayName(profile.getName());
values.setProfileUrl("https://www.facebook.com/app_scoped_user_id/" + profile.getId() + '/');
values.setImageUrl("https://graph.facebook.com/v2.2/" + profile.getId() + "/picture");
}
@@ -46,11 +46,11 @@ public class FacebookAdapterTest {
@Test
public void setConnectionValues() {
UserOperations userOperations = Mockito.mock(UserOperations.class);
Mockito.when(facebook.userOperations()).thenReturn(userOperations);
- Mockito.when(userOperations.getUserProfile()).thenReturn(new FacebookProfile("12345678", "Craig Walls", "Craig", "Walls", null, null));
+ Mockito.when(userOperations.getBasicProfile()).thenReturn(new FacebookProfile("12345678", "Craig Walls", "Craig", "Walls", null, null));
TestConnectionValues connectionValues = new TestConnectionValues();
apiAdapter.setConnectionValues(facebook, connectionValues);
assertEquals("Craig Walls", connectionValues.getDisplayName());
assertEquals("https://graph.facebook.com/v2.2/12345678/picture", connectionValues.getImageUrl());
assertEquals("https://www.facebook.com/app_scoped_user_id/12345678/", connectionValues.getProfileUrl());
from spring-social-facebook.
Related Issues (20)
- SocialContextOperations: return user picture in getAllMutualFriends response
- Offset is ignored
- Expected 3.0.0 Release HOT 4
- Missing encoding payload for Facebook
- Getting org.springframework.social.ExpiredAuthorizationException 1 min after login
- Add getTestUsers endpoint to TestUserOperations
- Is this a dead project? No Release for long time? HOT 8
- Upgrade to Graph API 2.10? HOT 2
- Configuration processor is not configured HOT 3
- End of support of Facebook Api v2.5 on 12 April 2018 HOT 8
- food_styles should be List<String> and not String from graph version v2.6
- Post video content to page
- Redirect_Uri use http instead of https with Spring social Facebook Login on Heroku HOT 8
- Insufficient permission - Unable to post to Facebook (similar response from linkedin api too)
- Not able to fetch accessToken. HOT 10
- API 2.9 disable in a few days. No release working with 2.10
- Facebook login exception after API 2.9 is disabled HOT 3
- Spring Social died on JULY 03, 2018
- Facebook login exception starting November 2020 HOT 1
- Cannot run build gradle eclipse due to Unauthorized
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-social-facebook.