How to get user Interests? - facebook-graph-api

This is not a duplicate of How can I get the interests of my friend through facebook api?. user_interests permission (to access /me/interests) is useless (if not deprecated) Facebook feature that hardly ever returns any data.
Instead, I am referring to the data aggregated by Facebook at this page:
These are all user likes grouped into categories like "Music", "Books", "TV Shows", etc. Generally, user likes can be retrieved through /me/likes. However, the latter query returns a rather vivid array of categories.
Is there a way to get user likes categorised into the same generic categories like Facebook does?

https://developers.facebook.com/docs/reference/api/user/:
The User object has the following connections:
books: The books listed on the user's profile.
games: Games the user has added to the Arts and Entertainment section of their profile.
movies: The movies listed on the user's profile.
music: The music listed on the user's profile.
television: The television listed on the user's profile.
The fields favorite_athletes and favorite_teams are deprecated, though. Not sure, if there will be any replacement for these analog to the above connections – or if users are just supposed to normally “like” the fan pages of athletes/teams in the future.

My approach to this issue is to process the API data within my application as such:
'Books' => array('Fictional Character', 'Writer', 'Book', 'Author', 'Book Store', 'Library', 'Magazine'),
'Films' => array('Actor/Director', 'Movie', 'Producer', 'Studio', 'Movie Theater', 'TV/Movie Award', 'Fictional Character', 'Movies/Music'),
[..]
e.g., if user likes "Writer" or "Book", I assign the like to "Books" category.
However, this solution is not ideal as Facebook might change category names, add new names, etc.

Related

Graph API: Posting as contributor to shared albums

Shared albums is a quite new feature of Facebook.
I'm encountering an issue with the Graph API while trying to publish photos to a shared album. The issue is actually related to the ID of the album.
As user A, I create an album getting the ID 1 and I add user B as contributor.
As user B, I can retrieve the album 1 using the Graph API but the "can_upload" flag is set to "false". Which prevents contributor B to upload photos to this album.
When I try to get the album's information as user B using facebook.com, it looks like the album has a different ID than 1, let's call it 2. When I retrieve album information as user B using ID 2 with Graph API, the "can_upload" flag is correctly showing "true".
Apparently the original's album ID is known as a different ID to album contributors. But how can I find out the ID allowing contributors to upload photos to it?
As there seems to be no API call to retrieve the ID (2) of the album to be used while publishing as contributor (user B), this is how one can manage to get it:
As user B (contributor), get the info of the album using its original
ID (1). Make sure to include field "cover_photo" in the request.
Get the info of the cover photo, using its ID retrieved above. Make
sure to include the field "link" in the request. Parse the "link"
field in order to retrieve the value of the parameter "set" which
contains the album ID.
Get the album ID by extracting it from the value above. The format is
something like "a.1234567890" or "a.1234567890.2345678901" where the
contributor's album ID (2) would be 1234567890.

How to show a list of registered users in Joomla?

I have hundreds of registered users. Those are grouped in different user groups:
See screenshot below (I changed this a little bit to protect my customers site):
Registered -> Teachers
Registered -> Students
How can I show a list of 'Teachers' online?
I want to list up all those teachers in a table or list, so that other teachers see this information.
Thank you. Any information is welcome.
You can use the following for to get the usernames from a specific user group:
$teachers = JAccess::getUsersByGroup(2); //change number in the brackets
$students = JAccess::getUsersByGroup(8); //change number in the brackets
foreach($teachers as $user_id) {
$user = JFactory::getUser($user_id);
echo $user->name;
}
foreach($students as $user_id) {
$user = JFactory::getUser($user_id);
echo $user->name;
}
Change "2" and "8" to the ID's of the Teachers and Students user groups.
Hope this helps
Personally, I think the best way to do that is to create a contact category teachers and then link each teacher to a contact record.
You can make a list of users in a group (there's even a method JAccess::getUsersByGroup() but I don't think it's that useful for this purpose. http://officialjoomlabook.com/school25/staff-directory is an example of where I did what I am suggesting.

URLs design for filtering Model's attributes in Django

Need you advice.
In my Django app I have a model for some Users. Users have some attributes: name, age, phone etc. This is not the API site. Just my intranet user's catalog.
I can get users using the following URLs:
/users/ # All users
/users/12 # User with ID 12
But how should I design URLs to get only the users which meet certain criteria? Is it a good practice to use query string for that purpose? Like this:
/users/ # All users
/users/?name=John # Filter by name
/users/?name=Peter&age=25 # Filter by name AND age
If the point is to display the same object list just filtered / sorted on a specific criteria (or set of) then yes, that's one of the purpose of query strings.

Artist info missing from Facebook Graph API /music.listens endpoint

I'm playing around w/ the /me/music.listens endpoint of Graph API and I have it working just fine. Except I can't seem to figure out how to get actual artist info to come back. I see the song and even the album (though that seems a little inconsistent too). But never any artist info.
Check the developer explorer here: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fmusic.listens
No artist info. Is this just not returned? I can't see how to specify this in a fields param list. FB's documentation of the actions is spotty at best so I figured I'd try here.
Thanks!
I've figured out a work around. It doesn't look like Facebook actually returns artist info. So you have to use the Spotify Lookup Service (http://developer.spotify.com/technologies/web-api/lookup/).
To break it down a little further, you start by pulling the music.listens feed from FB and you'll get info that looks like:
(
[song] => Array
(
[id] => 381659191902248
[url] => http://open.spotify.com/track/**2Vv27Gc5k5GgGW9jgtj1CS**
[type] => music.song
[title] => Follow Through
)
)
From there, you need to grab the bolded track ID.
Lastly, fetch the song metadata with this call to Spotify: http://ws.spotify.com/lookup/1/.json?uri=spotify:track:2Vv27Gc5k5GgGW9jgtj1CS
You'll be returned the album name, artist info, etc.
If someone knows a better way, lemme know!
You can retrieve artists informations on graph API with the song id :
https://graph.facebook.com/song_id?fields=data{musician}
ex : https://graph.facebook.com/697975930266172?fields=data{musician}
Old question I know, but you can retrieve related information such as both the song title and artist title in the same request using Graph API's 'field expansion'.
For example - Last 10 songs
me?fields=music.listens.limit(10){data{song{title,id},musician{id,title}}}
To retrieve more information from either the song or musician entities just tweak the fields requested.
Note, this requires user_actions.music permission

Django: structuring a complex relationship intended for use with built-in admin site

I have a fairly complex relationship that I am trying to make work with the Django admin site. I have spent quite some time trying to get this right and it just seems like I am not getting the philosophy behind the Django models.
There is a list of Groups. Each Group has multiple departments. There are also Employees. Each Employee belongs to a single group, but some employees also belong to a single Department within a Group. (Some employees might belong to only a Group but no Department, but no Employee will belong only to a Department).
Here is a simplified version of what I currently have:
class Group:
name = models.CharField(max_length=128)
class Department
group = models.ForeignKey(Group)
class Employee
department = models.ForeignKey(Department)
group = models.ForeignKey(Group)
The problem with this is that the Department select box on the Employees page must display all Departments, because a group has not yet been set. I tried to rectify this by making an EmployeeInline for the GroupAdmin page, but it is not good to have 500+ employees on a non-paginated inline. I must be able to use the models.ModelAdmin page for Employees (unless there is a way to search, sort, collapse and perform actions on inlines).
If I make EmployeeInline an inline of DepartmentAdmin (instead of having a DepartmentInline in GroupAdmin), then things are even worse, because it is not possible to have an Employee that does not belong to a Group.
Given my description of the relationships, am I missing out on some part of the Django ORM that will allow me to structure this relationship the way it 'should be' instead of hacking around and trying to make things come together?
Thanks a lot.
It sounds like what you want is for the Department options to only be those that are ForeignKey'ed to Group? The standard answer is that the admin site is only for simple CRUD operations.
But doing what you're supposed to do is boring.
You could probably overcome this limitation with some ninja javascript and JSON.
So first of all, we need an API that can let us know which departments are available for each group.
def api_departments_from_group(request, group_id):
departments = Department.objects.filter(group__id=group_id)
return json(departments) # Note: serialize, however
Once the API is in place we can add some javascript to change the <option>'s on the department select...
$(function() {
// On page load...
if ($('#id_group')) {
// Trap when the group box is changed
$('#id_group').bind('blur', function() {
$.getJSON('/api/get-departments/' + $('#id_group').val() + '/', function(data) {
// Clear existing options
$('#id_department').children().remove();
// Parse JSON and turn into <option> tags
$.each(data, function(i, item) {
$('#id_department').append('<option>' + item.name + '</option>');
});
});
});
}
});
Save that to admin-ninja.js. Then you can include it on the admin model itself...
class EmployeeAdmin(models.ModelAdmin):
# ...
class Media:
js = ('/media/admin-ninja.js',)
Yeah, so I didn't test a drop of this, but you can get some ideas hopefully. Also, I didn't get fancy with anything, for example the javascript doesn't account for an option already already being selected (and then re-select it).