Coder Social home page Coder Social logo

Comments (1)

digz6666 avatar digz6666 commented on June 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.