Get list of usernames based on userID - facebook-graph-api

I want to make a batch query similar to this:
SELECT name FROM user
WHERE uid IN (userID1, userID2, userID3 ...) and name LIKE '%searchParameter%'
Is this even possible? And how can I achieve this?

Yes it is possible
SELECT name, uid from user WHERE uid in (SELECT uid2 FROM friend WHERE uid1=me()) and strpos(lower(name),lower('Zuck')) >= 0
In the case above I'm querying for names from friends that include the letters zuck
http://developers.facebook.com/docs/reference/fql/user/

Related

How to give access to multiple users for same row in Data Studio for databases other than BigQuery?

To enable row level security, I used Filter By Email option as suggested here. But I want to know can I enable access to same row for multiple users and also how to enable super users who can see all rows. For example if below is the sample data then I want to have different output based on who is logged in.
userId age email
A 20 usera#gmail.com
B 15 userb#gmail.com
C 25 userc#gmail.com
Z 30 admin#gmail.com
When A is logged in
userId age email
A 20 usera#gmail.com
When B is logged in
userId age email
A 20 usera#gmail.com
B 15 userb#gmail.com
When Z is logged in
userId age email
A 20 usera#gmail.com
B 15 userb#gmail.com
C 25 userc#gmail.com
Z 30 admin#gmail.com
Update1 : I am using postgres instance for reporting (not bigQuery), so solution which make use of #DS_USER_EMAIL will not work
The filter by email simply provide you the email of the current logged user. You have to use it to filter your query. I designed a simple test like this
with sample as (
select "a" as userId, 10 as age, "usera#gmail.com" as email
UNION ALL
select "b" as userId, 20 as age, "userb#gmail.com" as email
UNION ALL
select "c" as userId, 30 as age, "userc#gmail.com" as email
), auth as (
select "usera#gmail.com" as user, "usera#gmail.com" as permission
UNION ALL
select "userb#gmail.com" as user, "usera#gmail.com" as permission
UNION ALL
select "userb#gmail.com" as user, "userb#gmail.com" as permission
UNION ALL
select "admin#gmail.com" as user, ".*" as permission
)
select * from sample
where REGEXP_CONTAINS(email,(select STRING_AGG(permission,"|") from auth where auth.user = #DS_USER_EMAIL))
I have the sample table with your data. I created a auth table with the link between the user email and the view authorization.
In the final request, I use a regex to check if the row is authorized or not. The admin has the value .* to view all the data. The other is simple an aggregation of all the rows, separated by a pipe | (OR in regex language)
EDIT
The power of BigQuery is the compliance with the SQL2011 standard, and a working query in postgres is similar. For the regex pattern use SIMILAR TO. Look at the admin regex pattern, it's not regex conventional, but it works
string_agg is an existing function
with sample as (
select 'a' as userId, 10 as age, 'usera#gmail.com' as email
UNION ALL
select 'b' as userId, 20 as age, 'userb#gmail.com' as email
UNION ALL
select 'c' as userId, 30 as age, 'userc#gmail.com' as email
), auth as (
select 'usera#gmail.com' as user, 'usera#gmail.com' as permission
UNION ALL
select 'userb#gmail.com' as user, 'usera#gmail.com' as permission
UNION ALL
select 'userb#gmail.com' as user, 'userb#gmail.com' as permission
UNION ALL
select 'admin#gmail.com' as user, '%' as permission
)
select * from sample
where email SIMILAR TO (select STRING_AGG(permission,'|') from auth where auth.user = #DS_USER_EMAIL)
The query works, but it's not usable with Datastudio because the #DS_USER_EMAIL exists only with BigQuery
The workaround is to use Cloud SQL federated query. And the final request is a mix between both db engine
with sample as (
SELECT * FROM EXTERNAL_QUERY("gbl-imt-homerider-basguillaueb.us.vertx-postgres", """ select 'a' as userId, 10 as age, 'usera#gmail.com' as email
UNION ALL
select 'b' as userId, 20 as age, 'userb#gmail.com' as email
UNION ALL
select 'c' as userId, 30 as age, 'userc#gmail.com' as email""")), auth as (
SELECT * FROM EXTERNAL_QUERY("gbl-imt-homerider-basguillaueb.us.vertx-postgres", """ select 'usera#gmail.com' as user, 'usera#gmail.com' as permission
UNION ALL
select 'userb#gmail.com' as user, 'usera#gmail.com' as permission
UNION ALL
select 'userb#gmail.com' as user, 'userb#gmail.com' as permission
UNION ALL
select 'admin#gmail.com' as user, '.*' as permission"""))
select * from sample
where REGEXP_CONTAINS(email,(select STRING_AGG(permission,"|") from auth where auth.user = #DS_USER_EMAIL))

How to search through rows and assign column value based on search in Postgres?

I'm creating an application similar to Twitter. In that I'm writing a query for the profile page. So when the user visits someone other users profile, he/she can view the tweets liked by that particular user. So for that my query is retrieving all such tweets liked by that user, along with total likes and comments on that tweet.
But an additional parameter I require is whether the current user has liked any of those tweets, and if yes, I want it to retrieve it as boolean True in my query so I can display it as liked in UI.
But I don't know how to achieve this part. Following is a sub-query from my main query
select l.tweet_id, count(*) as total_likes,
<insert here> as current_user_liked
from api_likes as l
INNER JOIN accounts_user ON l.liked_by_id = accounts_user.id
group by tweet_id
Is there an inbuilt function in postgres that can scan through the filtered rows and check whether current user id is present in liked_by_id. If so mark current_user_liked as True, else False.
You want to left outer join back into the api_likes table.
select l.tweet_id, count(*) as total_likes,
case
when lu.twee_id is null then false
else true
end as current_user_liked
from api_likes as l
INNER JOIN accounts_user ON l.liked_by_id = accounts_user.id
left join api_likes as lu on lu.tweet_id = l.tweet_id
and lu.liked_by_id = <current user id>
group by tweet_id
This will continue to bring in the rows you are seeing and will add a row for the lu alias on api_likes. If no such row exists matching the l.tweet_id and the current user's id, then the columns from the lu alias will be null.

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() )"
}

Appending Access Token to FQL Query

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

How get friends Check Ins since a date?

So i'm trying to get friends check ins form a specific date up to "now"
Like so:
search?type=checkin&since=1343613333633
(1343613333633 = 30 Jul 2012 01:55:33 GMT)
And I always get {"data":[]}
with out the "since" param i some check ins (all of them after that date)
i get the same results both on graph api explorer and from Android Facebook SDK (not sure if this is important)
How do i fix this?
Thx in advance.
You can easily use FQL to do it:
SELECT coords, tagged_uids, page_id, timestamp FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) and timestamp > 1312971542
will give you the list of friend checkins of the current logged in user since timestamp. Be sure to have the friends_checkins permission when retrieving the access token.