Facebook FQL query to get user's sent messages since a timestamp - facebook-graph-api

I'm not too familiar with Facebook FQL. I'm looking for a way to see what users have received my message. I know I need to ask for extended permissions read_mailbox
For instance I would like to see if my message "hello" has been sent after 2013-05-02 14:00 and which recipient userIDs has it been sent to.
Input for the query would be the message "hello" and from timestamp "2013-05-02 14:00" to current timestamp.
Output from the query would be a list of userIDs that have been sent the message "hello" since the timestamp 2013-05-02 14:00

After some trial and error I found a solution:
NSString *query = [NSString stringWithFormat:
#"{"
#"'query1':'SELECT thread_id FROM message WHERE thread_id IN "
#"(SELECT thread_id FROM thread WHERE folder_id = 1 AND updated_time >= \"%.f\") "
#"AND author_id = me() and body = \"%#\","
#"'query2':'SELECT recipients, thread_id FROM thread WHERE thread_id IN (SELECT thread_id FROM #query1)'"
#"}",
self.sendTime, self.facebookText];

Related

How can I get New Sender list over the years?

I have two tables: 1. Sender 2. Dates
In sender tables, i have data about the sender like sender name, product type, sending date, arriving date, cost, and much more. In the sender table, data is for two years: 2020 and 2021.
In 2021, New Sender has come. This new sender is not sending any packages in 2020. So I want to create a new table that only consists of data about the new sender.
How can do it with DAX?
Thank you.
You can do this by CreatingNewTable from DAX; Something like:
NewSenders =
var allSenders = VALUES('sender'[YourSenderID])
var SenderFromHistory = CALCULATETABLE(VALUES('sender'[YourSenderID]), 'sender'[Date] < DATEVALUE("2021-01-01"))
var OnlyNew = EXCEPT ( allSenders , SenderFromHistory )
return
CALCULATETABLE('sender', 'sender'[YourSenderID] in OnlyNew)

Issue related to fully distributed deployment of siddhi query with join operation

I have set up a 2 node worker and 1 node manager siddhi cluster.
Following is the query I tried pushing into manager. Everything seems to work fine when there is no join in the query, but in case of join as mentioned below query gets deployed in worker node but events dont seem to be satisfied.
#app:name("rule_1")
#source(
type="kafka",
topic.list="test-input-topic",
group.id="test-group",
threading.option="single.thread",
bootstrap.servers="localhost:9092",
#Map(type="json"))
define stream TempStream (deviceID string,roomNo string,temp int );
#sink(
type="kafka",
topic="test-output-topic",
bootstrap.servers="localhost:9092",
#Map(type="json"))
define stream OutStream (message string, message1 string, message2 double);
#info(name = "query1")
#dist(execGroup="group1")
from TempStream[deviceID=="rule_1" and temp>10]#window.time(5 sec)
select avg(temp) as avgTemp, roomNo, deviceID
insert all events into AvgTempStream1;
#info(name = "query2")
#dist(execGroup="group2")
from TempStream[deviceID=="rule_1" and temp<10]#window.time(5 sec)
select avg(temp) as avgTemp, roomNo, deviceID
insert all events into AvgTempStream2;
#info(name = "query3")
#dist(execGroup="group3")
from AvgTempStream1#window.length(1) as stream1 join AvgTempStream2#window.length(1) as stream2
select stream1.deviceID as message,stream1.roomNo as message1, stream1.avgTemp as message2
having stream1.avgTemp>stream2.avgTemp
insert into outputStream;
#info(name = "query4")
#dist(execGroup="group4")
from AvgTempStream1[deviceID=="rule_1"]
select deviceID as message, roomNo as message1, avgTemp as message2
insert into OutStream;
Event being passed
{"event":{"deviceID":"rule_1","roomNo":"123","temp":12}}
According to above given Siddhi app you will need to send two input event for it to make an output. One event with temp>10 other temp<10. Ex:
{"event":{"deviceID":"rule_1","roomNo":"123","temp":12}}
{"event":{"deviceID":"rule_1","roomNo":"123","temp":8}}
This will make sure that a join will happen and event will be emitted. For troubleshooting purposes you can subscribe to intermidiatory Kafka topics using Kafka consumer. Names of intermediate topics will follow the format of SiddhiAppName.StreamName. Ex: rule_1.AvgTempStream1
Hope this helps!!
Thanks,
Tishan

Getting all commets for an event with FQL

i am trying to list all comments for an event created by a certain page. I am getting the EID for for the event with a multiquery like this:
{ 'eids':'
SELECT eid, uid
FROM event_member
WHERE uid = 64565465464
'events':'
SELECT eid, name, venue, location, start_time, creator
FROM event WHERE eid
IN (SELECT eid FROM #eids)
AND creator = 64565465464 ORDER BY start_time ASC'}
I am totally clueless how to get the comments for that event with that EID.
Does anyone know how?
You will use the stream FQL table. The source_id on this table relates to the eid of the event table.
Example query via your above multi-query:
SELECT message FROM stream WHERE source_id IN (SELECT eid FROM #eids)
Docs: https://developers.facebook.com/docs/reference/fql/stream

FQL: Trouble joining tables where id is in format USERID_LINKID

I am running the following FQL via the php sdk:
{
"posts" : "SELECT post_id, actor_id, message, type FROM stream WHERE type = '80' AND message != '' AND filter_key in (SELECT filter_key FROM stream_filter WHERE uid='588853265' AND type='newsfeed') AND is_hidden = 0 ORDER BY created_time DESC LIMIT 50",
"actors" : "SELECT uid,name FROM user WHERE uid IN (SELECT actor_id FROM #posts)",
"links" : "SELECT owner, url FROM link WHERE link_id IN (SELECT post_id FROM #posts)"
}
I get results as expected for posts and for actors but not for links (results are empty). I believe the problem is that the link table uses a normal ID but my 'posts' from 'stream' show the ID in the format: USERID_LINKID.
I have played around with substr() and strlen() to get it to work with no luck.
There doesn't seem to be a way to get a link_id from a stream post. Your query is getting the id of the post, but not the link.
However, I don't think you need it. Get rid of the #links sub-query and add attachment to the SELECT statement in your #posts sub-query. You can get the link url at attachment->media->url.
One other critique: You might want to add additional sub-queries for #actors. The actor_id returned by the stream table can be a user, page, or group. Your FQL only resolves users. You'll end up with unknown IDs for links posted by groups and pages.

How to write FQL to fetch news feeds

I have to fetch all data which is on News Feeds (public wall). What query should I write ?
I wrote "SELECT likes,message FROM stream WHERE source_id = %lld limit 50 " query but it is returning my wall value. I want to fetch all data which is on my wall as well as on public (News Feed).
Thanks in advance
You need to use the filter_key to select the type of feed to use. The type you are after would probably be newsfeed, so the query could be something like this:
SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid = me() AND type = 'newsfeed')
For more information, have a look at the stream_filter docs.
How about doing it without querying FQL? :)
Use the Graph API instead:
https://graph.facebook.com/me/home?access_token=...
Try it on using "Graph API Explorer". /me/home