Facebook Profile Pictures for non-Friends - facebook-graph-api

I am creating an iPhone email client that displays sender's profile pictures in in the UITableViewCells in the inbox, much like Sparrow does. I am using the following FQL query to grab these images:
SELECT
pic_big
FROM
user
WHERE
uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
AND
strpos(lower(name),'INSERT_FIRST_THREE_LETTERS_OF_FIRST_NAME_HERE') >= 0
AND
strpos(lower(name),'INSERT_LAST_NAME_HERE') >= 0
ORDER BY name
I get the names of the senders from the email headers, and then search the user's Facebook friends using the full last name and the first three letters of the first name to account for nicknames. This works pretty well on the whole.
Sparrow, however, is able to grab profile pictures from Facebook for users I am not even friends with. How is this possible? I though queries were limited to specific groups, like your friends. And that searches for email addresses were not valid? Is this correct? How does Sparrow grab these profile pics?

Well as long as you know the users Facebook ID - it's a long number but treat it as a string. You can use this url to get their profile picture:
https://graph.facebook.com/[id]/picture
No need for anything more complex.

You can get the user_id of any known user from their email by making an API call to:
/search?type=user&q=USER#EMAIL.NET
If their email is registered with Facebook and public, you'll get back a JSON object with their name and user id. You'll need to make a separate call (or use a batch request) to get their picture from their ID.

Related

How can I add users to a Facebook group automatically?

The flow I'm going for is:
User signs in with Facebook to our site.
User pays a fee using PayPal or some similar service.
User is allowed access to a particular Facebook group.
I'm not particularly fussy about how the process works, but I'd like to avoid a manual step if possible.
I know I can't invite them using the Graph API (as they're not an admin, developer or tester of the app). But is there some other way round? A button that allows them to request access that I then confirm using the API? An automatic way of emailing an invite?
Or is there a way of making it easier to do the manual step? Some way of listing the new users with an "invite to group" button? A friend request button for the user to press?
With facebook API you can't do this with a normal group, but you can use app groups instead. To create an app group, you have to do a POST request to this url:
http://graph.facebook.com/{your-app-id}/groups
with the following informations:
valid app access token
name: the name of the group
description: the description of the group
privacy: enum, it can be open or closed
admin: admin's user id
Then you will recive a gropu ID. You can get info about your group ith a GET request to this URL:
http://graph.facebook.com/{group-id}
EDITED: You can no longer add members with POST request, but there is an another way.
New solution
You can use a client-side dialog to add members to groups. You can find the documentation here: https://developers.facebook.com/docs/games/app-game-groups/v2.0#add_user
I tested it with a user who wasn't a tester, andd it works fine.
Old solution (no longer available)
You can add members to this group with a POST request to this URL:
http://graph.facebook.com/{group-id}/members
You have to post:
valid app access token
member: user ID of the person to invite
The person will recive something like this image:
(source: edemmester.hu)
I tested it, it works fine.
More info about app groups: https://developers.facebook.com/docs/graph-api/reference/v2.0/app/groups
IMPORTANT! You have to use app access tokens here, not user access tokens.
I don't think it's possible to invite people without writing a browser extension that has access to the cookies etc. of the logged-in group admin.
Anyway, you cannot simply add people to a group if you're not friends with them, but need to invite them by email. So probably it's easiest if you ask them for their email-address and then invite them by email.

How to get all facebook events?

I'm building a django app and I'm interested if there is a way to get all the newest/popular events from facebook.
I want to get their title, location, description etc.
EDIT:
For the solution in the answer bellow to be successful i'll need the access token. It can't be done with the app token. Also I don't need to search through events but retrieve them sorted by popularity.
Since i'm using django facebook for now i can get my users friends events (in which they are participating). Is there another way to retrieve them through the API?
https://developers.facebook.com/docs/reference/api/
Look for the headline "Searching":
https://graph.facebook.com/search?q=conference&type=event
You need an access token for it, but i guess an app access token will do:
$app_access_token = APPID . '|' . APPSECRET;
The app access token is valid as long as you donĀ“t change the id and secret of the app (will most likely never happen).
EDIT:
If you take a look at the FQL table of the events, there is no field for the "popularity":
https://developers.facebook.com/docs/reference/fql/event/
...so i guess you mean sorting by "most attending people". But you wrote "all the newest/popular events from facebook", so that means all events and not only those of the logged in user and his friends. The only way to get the events in that case is the solution i presented above.
If you want to get the Events of the user, FQL would be the correct way, i guess:
SELECT name,description,location,attending_count from event WHERE eid in (SELECT eid FROM event_member WHERE uid = me()) ORDER BY attending_count DESC
This gives you all events of the user, sorted by the number of attending people.

Can't read achievements for certain users

I'm experiencing some inconsistent behaviour when trying to read achievements from my app. I have 3 tests accounts, 2 of which I can read achievements. However the 3rd account always returns an empty array. All 3 accounts have the publish_action permission and I've tried using both the user and app access_token. Here's the query:
https://graph.facebook.com/{uid}/achievements?access_token={app_access_token}
or
https://graph.facebook.com/{uid}/achievements?access_token={user_access_token}
Now I know the 3rd account has achievements as I get an error when I try to give it an achievement it already has and the game ticker correctly shows the achievements it has earned.
Make sure the third user has granted "user_activities" extended permissions so that the activities can be read, not just published. You can verify this by calling /me/permissions.
Have you checked the facebook layout regarding achievements in your app? since in my FB account I can roll over my own achievements and I get a full list of the achievements configured with each game and in other acocunt that info is not available. The other distinctive feature is I see my thumbnail picture over the main facebook bar (the blue one next to log in)

email id of user from new facebook API

I have worked earlier on facebook API. I successfully used it and fetched all friend lists with their email ids. I was also able to get user email id who logged in through facebook API.
Now in gap of 7-8 months I found that faceAPI development section has been changed . New one is something different.
And now I am facing problem to get email id after user login at facebook.Yet all other details are coming like user name .user id and location except email id.
Old script is also not working with me. Could you help me to get email id of user who get login by facebook at my website.
Thanks for your cooperation.
No one will do your homework (upgrade the code for you)
Read the most current documentation
Accessing users e-mails require a special permission email
Users may choose not sharing their direct e-mail with you
You didn't say what technology you are using, but you can check the PHP-SDK example page to get started.
Direct Access Method:
Log into Facebook under your name. If you need an "Access Token", Click on the Extended Permissions and click the "read_friendlist" check box to get your Access Token and then
submit your query. You may need to "Allow" access, so just follow the prompts given.
Voila! You now have the usernames for everyone on your Friends List. The "username" parameter in the query will give you the contact email "message to that person" and you append #facebook.com and send them a message. Very simple.
http://developers.facebook.com/tools/explorer?fql=SELECT%20username%20FROM%20user%20WHERE%20uid%20IN%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%29%20ORDER%20BY%20name
I had been using the import function in Yahoo Mail but now it has been limited to the first 50 names on your friends list. Where I work, they have over 6,000 friends between the two pages. This is a very simple solution to my problem. And now I can write a very small PHP sendmail program and send EVERYONE on the friends list an email message that goes directly to their messages. No more viewing page sources or manually doing this.
I can create a special email list on IFanz that will handle all dups, even if I repeat this process on a monthly basis to acquire new emails.
-SAB

FQL query for photos returns photos from hidden (blocked) users. How to prevent this?

I request latest photos for a user using an FQL query, like the one below:
SELECT pid, aid, owner, src_small, src_big, src, link, caption, created FROM photo WHERE aid IN (SELECT aid FROM album WHERE owner IN (SELECT uid2 FROM friend WHERE uid1=) ORDER BY modified_major DESC LIMIT 300) ORDER BY created DESC LIMIT 500
It works well but I believe it doesn't respect the setting where the user block specific users on the facebook page. So in my app, he sees all the photos, and he's not happy :).
Now, I see that in user table there's is_blocked property, but it's not indexed so I can't use it in a WHERE clause. I also don't want to call FB for every user I get just to check for that property and filter based on that in the app itself.
So, first of all, am I correct that this query doesn't respect blocked users settings?
If yes, is there a way to respect this setting using FQL?
You may look at privacy table. There is id column which represent an image object as well and deny field with a list of users that cannot see the object. I think you should use a fql.multi-query to resolve this. Some info about fql.multi-query you can find at this topic.