Trying to run this in the Graph API Explorer:
"query1":"SELECT uid, message FROM status where uid in (SELECT uid2 from friend where uid1 = me())"
"query2":"SELECT name from user where uid in (select uid from #query1)"
But all I get is:
{ "data": [ ] }
I'm completely new into this. What am I doing wrong?
You most likely have a formatting issue
fql?q={"query1":"SELECT uid, message FROM status where uid in (SELECT uid2 from friend where uid1 = me())", "query2":"SELECT name from user where uid in (select uid from #query1)"}
Works fine for me.
Related
I want to run 2 queries in django, I am using mysql, Please help me
first one
SELECT * FROM `invitations`
WHERE post_id = 19215 GROUP BY (user_id)
it is not group by from user_id
data = Invitations.objects.filter(post_id=19215).annotate(user_id=Count('user_id'))
now i have add value
data = Invitations.objects.values('user_id').filter(post_id=19215).annotate(user_id=Count('user_id'))
it return me not all fields select *
data = Invitations.objects.values('user_id', 'xyz').filter(post_id=19215).annotate(user_id=Count('user_id'))
it group by user_id and xyz
Please give me solution
and second is
SELECT *, GROUP_CONCAT(interview_mode) FROM invitations WHERE post_id = 19215 GROUP BY (user_id)
Run this:
query= "SELECT *, GROUP_CONCAT(interview_mode)
FROM invitations WHERE post_id = 19215
GROUP BY (user_id)"
data = Model.objects.raw(query)
sql query:
SELECT *
FROM "notification_notification" AS T0
LEFT JOIN (SELECT *
FROM "notification_usernotification"
WHERE user_id = 1) AS T
ON (T0.id = T.notification_id)
models:
class Notification(models.Model):
subs_code = models.CharField()
subs_name = models.CharField()
users = models.ManyToManyField(settings.AUTH_USER_MODEL,
through='UserNotification')
class UserNotification(models.Model):
notification = models.ForeignKey(Notification)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
push_message = models.BooleanField()
Is it possible?
i try various technique, but i can't create that simple sql under django ORM;
notification_notification table AS T0
|---id---|-----subs_code-----|-----subs_name-----|
|---1----|-----system----------|----system------------|
|---2----|-----broadcast------|-----broadcast-------|
|---3----|-----not_need-------|-----not_need-------|
notification_usernotification table AS T1
|---id---|-notification_id-|-user_id-|-push_message-|
|---11--|---------1----------|----1------|--------true---------|
|---12--|---------2----------|----1------|--------false--------|
|---22--|---------2----------|-----2-----|--------true---------|
i use left join for that result:
Result:
|-T1.id-|-subs_code-|-subs_name-|-T1.id-|-notification_id-|-user_id-|-push_message-|
|---1----|---system----|---system-----|---11--|------------1-------|---1-------|----true-------------|
|---2----|---broadcast|---broadcast--|--12---|------------2-------|---1-------|----false-----------|
|---3----|---not_need-|---not_need--|--null-|---------null--------|---null----|----null-------------|
INNER JOIN is not valid there are ((
sqlfiddle
i think it possible only for raw sql
it write raw sql query.
it write by extra: see in here stackoverflow
Notification.objects.extra(
select={
'push_message':
'SELECT {tbl_1}.push_message::BOOLEAN FROM {tbl_1} '
'WHERE {tbl_1}.notification_id = {tbl_2}.id '
'and {tbl_1}.user_id = %s'.format(
tbl_1=UserNotification._meta.db_table,
tbl_2=Notification._meta.db_table)},
select_params=(user.id,))
FQL Query
SELECT name, online_presence IN ('active', 'idle') FROM user WHERE online_presence IN ('active', 'idle') AND uid in(SELECT uid2 from friend where uid1= me())
By This Query I am getting friends
Please Anyone Tell Me how can I message these online friends.
Method 1:
Assume:
Your app id is "87741124305"
"4" is one of your friend uid get from FQL query:
SELECT uid, name, online_presence FROM user WHERE online_presence IN
('active', 'idle') AND uid in(SELECT uid2 from friend where uid1=
me())
you want to share a link "https://www.youtube.com/watch?v=VM56POaEEX4"
https://www.youtube.com/facebook_redirect is your app CANVAS_URL
The full link would be:
https://www.facebook.com/dialog/send?app_id=87741124305&to=4&link=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVM56POaEEX4%26feature%3Dshare&redirect_uri=https%3A%2F%2Fwww.youtube.com%2Ffacebook_redirect
Method 2:
Send email to him.The email address is in the form USERNAME#facebook.com You can get the USERNAME via FQL query:
SELECT uid, username, online_presence FROM user WHERE online_presence
IN ('active', 'idle') AND uid in(SELECT uid2 from friend where uid1=
me())
Please note that, some user doesn't have username. Also, you can't send empty body message.
Method 3:
You may refer to https://developers.facebook.com/docs/chat/ for Jabber/XMPP service.
I am using following query to find gender of app user.
q=select gender from user where uid=user_id
but the output is
"error": {
"message": "(#602) gender is not a member of the user table.",
"type": "OAuthException",
"code": 602
}
I have seen gender in user table on facebook api,
where is the problem??
Gender is represented as "sex" column in users table.
you can do like this : q = select sex from user where uid=user_id.
For more reference check this : http://developers.facebook.com/docs/reference/fql/user/
does facebook support field of filed for graph api?
For example,
https://graph.facebook.com/[uid]/friends/?fields=events
will give all friends and their events.
Can I also control which field i want in the events by doing something like
<https://graph.facebook.com/[uid]/friends/?fields=events,events__updated_time>
Thanks
You can't do this directly through the Graph API, however the best thing to do with more complex queries is to look into FQL. In your specific example, you can do something like this:
SELECT eid, update_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()))
You can run this against the Graph API by doing:
https://graph.facebook.com/fql?q=SELECT eid, update_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()))
Test this using the Graph API Explorer