8

I'm currently working on an alternative way to view the threads and messages. But I have problems figuring out how to display the images attached to a message.

I have a GET request to this url: https://graph.facebook.com/t_id.T_ID/messages?access_token=ACCESS_TOKEN. And the response includes

"attachments": {
   "data": [
      {
         "id": "df732cf372bf07f29030b5d44313038c",
         "mime_type": "image/jpeg",
         "name": "image.jpg",
         "size": 76321
      }
   ]
}

but I can't find any way to access the image.

Thanks

ThoKra
  • 2,959
  • 2
  • 27
  • 38
  • 1
    is it just me, or does the graph api no longer expose attachment id's like this? – Justin L. Aug 30 '12 at 02:02
  • It's bug, it's been reported: https://developers.facebook.com/bugs/153137724878722?browse=external_tasks_search_results_52517d949d48d3494815922 – Raffael Oct 06 '13 at 15:12

1 Answers1

12

Support for this hasn't yet been added to the Graph API and as with many of the other messaging APIs, it's currently only avaialable for testing (i.e you must be a developer of the app to use it presently)

There's an undocumented REST API endpoint for this, which should work for any app (that you're the developer of, as above).

To use the REST method to get the attachment data, it's

https://api.facebook.com/method/messaging.getattachment

With parameters:

access_token=YOUR_ACCESS_TOKEN
mid=MESSAGE_ID
aid=ATTACHMENT_ID
format=json     //(it defaults to XML otherwise)

The response is like this:

{"content_type":"image\/png","filename":"Screen Shot 2012-02-08 at 11.35.35.png","file_size":42257,"data":<FILE CONTENTS>}

I've just tested this and it worked OK for me, taking the <FILE CONTENTS> and base64 decoding them gave me back the original image correctly

Igy
  • 43,710
  • 8
  • 89
  • 115
  • The question asker included that in their question, it's attached in a call to `/THREAD/messages` – Igy Jul 11 '12 at 08:59
  • SELECT message_id, thread_id, author_id, body, created_time, viewer_id, attachment FROM message WHERE thread_id = 357563430998275 ORDER BY created_time DESC LIMIT 100 OFFSET 0. This my request for getting messages with attachments, but attachmentID not returning and url to attachment file is not correctly, What is there may be Problem? – Shamsiddin Saidov Nov 16 '12 at 07:51
  • i keep getting this response: {"error_code":3,"error_msg":"Unknown method","request_args" followed by all my params, any idea why this is? Is this endpoint still working? – maxandonuts Feb 28 '15 at 17:28