Appending Access Token to FQL Query - facebook-graph-api

Is there a way to append my long term access token to the query given at Getting Facebook Events using fql ? The query at that link is
fql?q={"event_info":"SELECT name,description, pic_small,pic_big, eid,venue,location from event WHERE eid in (SELECT eid FROM event_member WHERE uid = me())", "event_venue":"SELECT name, username, page_id, location FROM page WHERE page_id IN (SELECT venue.id FROM #event_info)"}
Thanks in advance for any assistance...
UPDATE - The answer provided worked like a charm. THANK YOU!

Yes. Try this:
/fql?q=QUERY&access_token=TOKEN

Related

Replace Traffic Source from raw Google analytics session data in Bigquery?

Recently we observed that when a user tries to complete a transaction on our website using an ios device. Apple ends the current session and begins a new session. The difficulty with this is that if the user came through paid source/email the current session ends and starts a new session with apple.com traffic source.
For Instance
google->appleid.apple.com
(direct)->appleid.apple.com
email->appleid.apple.com
ios->appleid.apple.com->appleid.apple.com->appleid.apple.com
Since we have this raw data coming into BQ we are looking at replacing appleid.apple.com with their actual traffic Source i.e. google,direct,email,ios.
Any help regarding the logic/function to workaround this problem will help?
This is the code I tried implementing:
WITH DATA AS (
SELECT
PARSE_DATE("%Y%m%d",date) AS Date,
clientId as ClientId,
fullVisitorId AS fullvisitorid,
visitNumber AS visitnumber,
trafficSource.medium as medium,
CONCAT(fullvisitorid,"-",CAST(visitStartTime AS STRING)) AS Session_ID,
trafficsource.source AS Traffic_Source,
MAX((CASE WHEN (hits.eventInfo.eventLabel="complete") THEN 1 ELSE 0 END)) AS ConversionComplete
FROM `project.dataset.ga_sessions_20*`
,UNNEST(hits) AS hits
WHERE totals.visits=1
GROUP BY
1,2,3,4,5,6,7
),
Source_Replace AS (
SELECT
Date AS Date,
IF(Traffic_Source LIKE "%apple.com" ,(CASE WHEN Traffic_Source NOT LIKE "%apple.com%" THEN LAG(Traffic_Source,1) OVER (PARTITION BY ClientId ORDER BY visitnumber ASC)end), Traffic_Source) AS traffic_source_1,
medium AS Medium,
fullvisitorid AS User_ID,
Session_ID AS SessionID,
ConversionComplete AS ConversionComplete
FROM
DATA
)
SELECT
Date AS Date,
traffic_source_1 AS TrafficSource,
Medium AS TrafficMedium,
COUNT(DISTINCT User_ID) AS Users,
COUNT(DISTINCT SessionID) AS Sessions,
SUM(ConversionComplete) AS ConversionComplete
FROM
Source_Replace
GROUP BY
1,2,3
Thanks
Does assuming the visitStartTime as key to identifying the session start help? Maybe something like:
source_replaced as (
select *,
min(Traffic_Source) over (
partition by date, clientid, fullvisitorid, visitnumber order by visitStartTime
) as originating_source
from data
)
Then you can do your aggregation over the originating_source. Its kind of difficult without looking at some sample of data about whats going on.
Hope it helps.

Get all friends' ids who liked a post

I am using Facebook FQL to query stream table. I want to get the list of all user ids of friends who liked one of my post. Here is my query:
select post_id,likes.friends, likes.count from stream where source_id = me() and likes.count > 0 limit 200"
However, I only get maximum 4 friend ids in return, even if likes.count > 4, which is exactly like likes.sample.
Is this a bug, or a limitation of FQL? If I can't get full list of Likers here, which table I should look at? If this is not feasible with FQL, how can I make a similar query in Graph API?
Thank you.
Use a multi-query on the stream and like tables
{"posts": "select post_id, likes.count from stream where source_id = me() and likes.count > 0 limit 200",
"friends_who_like_posts":"select user_id FROM like WHERE post_id IN (SELECT post_id FROM #posts) AND user_id IN (SELECT uid2 FROM friend WHERE uid1 = me() )"
}

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