0

I would like to know how to use the following fql query to get a single message from my facebook inbox using facebook sdk for php (or another way if it's possible )

https://graph.facebook.com//fql?q=SELECT+body+FROM+message+WHERE++mssage_id="XXXXXXXXXXXXXXXXX_XXX"&access_token=...

(returns a JSON result)

OR

https://api.facebook.com/method/fql.query?query=SELECT+body+FROM+message+WHERE+message_id="XXXXXXXXXXXXXXXXX_XXX"&access_token=...

(returns an XML result)

both methods need an access token for a read_mailbox permission. All i need is to get the result using php. Any help ?

Thanks.

1 Answer 1

1

The most flexible way is to use the api method of the PHP SDK. The Facebook documentation site has examples of this.

If you already have an access token, this code will get you the data into a php array:

<?php $query = 'SELECT body FROM message WHERE message_id = "?????????????_??"'; $token = '????'; $result = json_decode( file_get_contents('https://graph.facebook.com/fql?q=' . urlencode($query) . '&access_token=' . $token) ); printf('<pre>%s</pre>', print_r($result, true) ); 

Yes you need an access token for this. If you're trying to read the mailbox of a random user, you need an app, and you'll have to follow one of the authentication workflows to get them to log into your app and give you the read_mailbox permission.

Sign up to request clarification or add additional context in comments.

8 Comments

Well, i am trying to read my own inbox, i have the right access token with read_mailbox permission. It's just that the file_get_contents function never worked for me before with facebook, just like the little code example you gave.
How does it not work? You should at least be getting an error back.
returns nothing at all, blank ! You can try
@cpilko, why’re you talking about “using the API method of the PHP SDK” at first, and then explicitly don’t use it in your sample code, but file_get_contents instead? FQL queries work perfectly fine using Facebook::api().
@CBroe: A solution with Facebook::api(), requires more prerequisites on the OP's part, which I'm not sure he is ready to follow. I've linked do the docs if he's ready to follow that path. With the OP's original assumption of a known message_id and access_token, file_get_contents gives a minimal viable solution. I posted a live example using the above code to show that it indeed works (which I've since deleted).
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.