Get profile photos when reading a page's feed

21 views
Skip to first unread message

Milad Vadoodparast

unread,
Jun 27, 2019, 3:47:54 AM6/27/19
to RestFB
Hi,

Each post within a page's feed contains a "from" which refers to the poster of that post. To get the profile photos of these "from" guys while reading the feed I'm doing:

me/feed?fields=from{picture.type(large)}

Since a post's "from" in RestFB resolves to a CategorizedFacebookType object and it doesn't have a "picture" property, I couldn't find a way to retrieve the picture's URL.


Is the only way to get this link is making another request based on the description provided here, or is there a workaround to retrieve this from the response json?

Thanks

Norbert Bartels

unread,
Jun 30, 2019, 7:04:24 AM6/30/19
to RestFB

Hi Milad,

I see the problem. Because you only need the from field and its picture, I suggest to define a new class like, let’s say PostFrom.

public class PostFrom {

     @Facebook
     private User from;

     public User getFrom() {
          return this.from;
     }
}

And then use the PostFrom in the connection.
Hope this helps.

best regards

Norbert

Milad Vadoodparast

unread,
Jul 2, 2019, 3:01:57 AM7/2/19
to RestFB
Hi Norbert,

Thanks for your reply.

Actually, the "from" was just an example. I'm asking for a lot of the fields including the admin_creatorstory_tags, message_tags, etc which all contain a picture. 

I imagine extending the post class is not feasible since it already contains from, story_tags ,etc. Am I right?

The second issue that I faced while using your proposed method was that when using the DefaultJsonMapper to generate the json of PostForm, the picture was recognized as a primitive data type and was serialized as a string.

What I finally did was cloning the whole project and adding picture to the NamedFacebookType class. That still has the picture json issue but I imagine that can be fixed by a custom json mapper.

Are there any side effects with adding the picture to that class? Would you recommend any other workarounds? 

Thanks again,
Milad

Norbert Bartels

unread,
Jul 2, 2019, 10:13:24 AM7/2/19
to RestFB
Hi Milad,

okay, I see the problem. I already thought about changing the from field to User, but it may be of a different type. For example a page could be the sender of a post and then it would be very misleading. ATM I have no good idea for this.

Normally you receive a url that points to Facebook's CDN. So it is only a String. Do you have any other experience here? Would be very interesting.

We try to have the types as small as possible and don't provide fields that can be filled by Facebook. Therefore I will not a picture to the NamedFacebookType in the library, but you can add it to your custom types.
BTW it is possible to have two fields with the same Facebook field. The Mapper can handle this. So you can write your custom type and add some more fields with the same Facebook annotation name but different objects.

Hope this helps

Norbert
Message has been deleted

Milad Vadoodparast

unread,
Jul 2, 2019, 8:21:24 PM7/2/19
to RestFB
Thanks Norbert and apologies for the duplicate emails,

If I use 'User' for 'From', I get something similar to this for 'picture' when I use the DefaultJsonMapper'toJson method: 


So apparently, instead of converting ProfilePictureSource into json, it's using 'rawPicture' which is the one annotated with @Facebook. 

And for the 'NamedFacebookType', I guess I'll go with the approach you described which is extending it, adding a picture and then tweaking the mapper. 

Cheers,
Milad
Reply all
Reply to author
Forward
0 new messages