Hi,
I've got a requirement to be able to manage pages private messages, which is fine, I can get the conversations, I can reply etc. When it came to testing what happens when I add a photo I fetched the JSON to find they are in the result for each message as 'attachments', and that I couldn't get to this by default in RestFB. I also found you can view attachments separately as m_id.xxxxx/attachments but that's not required as they seem to come with the regular message/conversation call.
"attachments": {
"data": [
{
"id": "b78ffab9a306e8b0a12c57f939b76",
"mime_type": "image/jpeg",
"name": "13765735334.jpg",
"size": 350567
}
]
}
I tried for a while to find an inbuilt way to do it and then settled on modifying the Message class and adding a new class called Attachment, just keeping it in line with how Comments are included with a Post.
It works fine as far as I can see it and is allowing me to get back enough info to create a URL pointing to the image but I just wonder if I'm missing something, or is this how it would be expected to do to?
I've included the additions I made below, just in case anyone else reading this has the same requirement.
Thanks,
Alan.
Attachment.javapackage com.restfb.types;
import com.restfb.Facebook;
/**
* Represents an attached picture that you may find on a private message
* @author alockhart
*
*/
public class Attachment extends FacebookType {
private static final long serialVersionUID = 1L;
@Facebook
private String name;
@Facebook("mime_type")
private String mimeType;
@Facebook
private Long size;
/**
* Returns the size of the attachment, like 350567
* @return
*/
public Long getSize(){
return size;
}
/**
* Name of the attachment, like 121423423.jpg
* @return
*/
public String getName(){
return name;
}
/**
* Mime type of attachment, like image/jpeg
* @return
*/
public String getMimeType(){
return mimeType;
}
}
Addition to Message.java @Facebook
private Attachments attachments;
/**
* Represents picture attachments etc
* @author alockhart
*
*/
public static class Attachments implements Serializable {
@Facebook
private Long count;
@Facebook
private List<Attachment> data = new ArrayList<Attachment>();
private static final long serialVersionUID = 1L;
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return ReflectionUtils.hashCode(this);
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object that) {
return ReflectionUtils.equals(this, that);
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return ReflectionUtils.toString(this);
}
/**
* The number of comments.
*
* @return The number of comments.
*/
public Long getCount() {
return count;
}
/**
* The comments.
*
* @return The comments.
*/
public List<Attachment> getData() {
return unmodifiableList(data);
}
}