How do I access friends likes with FQL? I can see it in the Graph API:
https://graph.facebook.com/1111111/likes
... but I can't seem to figure out how to do it in FQL.
fql?q=SELECT uid, page_id from page_fan where uid IN(SELECT uid2 from friend where uid1=me())
You can try this in your api explorer to get user friends likes.
You can do this by querying url_like table:
SELECT url FROM url_like WHERE user_id IN (
SELECT uid2 FROM friend WHERE uid1 = me()
)
You cannot however get list of likes by friends for: photo, album, event, group, note, link, video, application, status, check-in, review, comment, post.
This info is located in like table but to query it based on user_id you need read_stream permissions from that user...
EDIT: Added Graph API Explorer Example to easily preview this:
http://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20url%20FROM%20url_like%20WHERE%20user_id%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me())
Related
I have two models user and recordings, But I don't have any relation between them I have stored user id in recordings (there can be multiple recordings of one user). and I want the latest recording of user with user object how can I achieve that
class Recording(models.Model):
userid = models.IntegerField()
Hi welcome to stackoverflow.
Please ask your question with some of your code.
I think you can try this:
users = User.objects.all().extra( select={
'last_reco':
'SELECT recordings.field_name FROM recordings WHERE '
'recordings.userid = '
'User.id ORDER BY id DESC LIMIT 1',
})
note: recordings is your recording db name
Than you can access last recording with last_reco attr of user object
I am using Django and rest-auth. I already have a working code to fetch today's and yesterday's login counts in my Django application as follows:
def get_analytics(request):
total_users = User.objects.all().count()
total_users_games = User.objects.filter(username__startswith='yg_').count()
# Number of users who dogged in once to our system today
today_login_count= User.objects.filter(last_login__startswith=timezone.now().date()).count()
today_login_count_memoryGames= User.objects.filter(last_login__startswith=timezone.now().date(), username__startswith='yg_').count()
yesterday_login_count = User.objects.filter(last_login__startswith=timezone.now().date() - timezone.timedelta(days=1)).count()
yesterday_login_count_memoryGames = User.objects.filter(last_login__startswith=timezone.now().date() - timezone.timedelta(days=1), username__startswith='yg_').count()
There are usernames starting with 'yg' and few starting with 'yg_' responsible for two different frontends.
Today's login count is correct, I crosschecked from database. However I am not sure about yesterday's login count, it looks like the number which I get is not correct (i.e. today's login count will be tomorrow: yesterday's login count, so these numbers should be same). I suspect the code for yesterday's login count gives me those users who did login yesterday and not today, where as what I want is all the users who logged in yesterday. I ran following query with yesterday's date and got 4 results and that's actually what
yesterday_login_count_memoryGames = User.objects.filter(last_login__startswith=timezone.now().date() - timezone.timedelta(days=1), username__startswith='yg_').count()
gives me.
select username, last_login from auth_user where username like '%yg\_%' and last_login like '%2016-09-06%';
I am cross checking in my database with following sql query:
select username, last_login from auth_user where username like '%yg\_%' and last_login like '%2016-09-07%';
How can I write a query to fetch yesterdays's login count like this?
Also, in this line username__startswith='yg_' do I need escape character? like username__startswith='yg_'? to get the count of logins with usernames starting with yg_?
Relying on last_login isn't going to cut it and will give unreliable data. You will need to store each successful login event in another table foreign keyed to the user along with the login time.
class LoginEvent(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
login_date = models.DateField()
Note that you wont need to store more than one login in a day. When a user logs in, check if an entry with todays date exists or not. If it exists, then do need not do anything. If it doesn't exist, you will need to insert a new row with todays date. You could even set up a unique_together constraint for ('user', 'login_data') to enforce this.
After this, the following query will be able to give you the login count data you need.
yesterday = timezone.now().date() - timedelta(days=1)
LoginEvent.objects.filter(login_date=yesterday, user__username__startswith='yg_').count()
This will create the necessary inner join and give you the counts.
I am trying to create an album in some Facebook test users using V2.2. I tried couple of APIs (as below)
POST http://graph.facebook.com/{user-id}/albums (passed "Name" field with value)
POST http://graph.facebook.com/v2.2/me/albums (passed "Name" field with value)
As a response I get some "id". I believe that's the album id. But when I cross check using client by login in to user account -> Photos, I don't see any album created there.
Can somebody assist with the same?
I am looking for optimized FQL way getting latest photos per user_id, the only one I can think now is to get aid's (album id's) and query each aid for photos ... (this is lots of querying)
You can use subquery, should be like so:
SELECT object_id, src_small
FROM photo
WHERE aid IN (SELECT aid FROM album WHERE owner = me())
ORDER BY created DESC LIMIT 1
hope this helps
I ask for the wall posts of a user and I also get the posts of other people who posted there.
How do I post ONLY the posts of the user?
In FQL:
SELECT post_id, message FROM stream WHERE source_id = <uid> AND actor_id = <uid>
If both source_id and actor_id are the same you will get only that user's posts to his own wall. (See http://developers.facebook.com/docs/reference/fql/stream)
Is that what you are trying to do? What have you got so far?