How-To: Grab user data and store it into Drupal?
I have been tasked here at work to use one of our web sites we use and get it connecting to facebook and pulling in user data based upon if the user allows it.
I have read though a few threads here and it seems that the basics works so far
User account created , profile image is pulled in but getting any other information doesn't seem to work. I would like to see if anyone would want to work on a combined effort to try to hash out why I cant get things like user_hometown to populate on drupal.
Here is what I have done so far:
I have modified the fb_permissions.module in the contrib folder to add all relevant data that you might want to get from the user.
you can see a list of valid data you can get if the user allows it:
http://developers.facebook.com/docs/authentication/permissions
it also seems to me that the TOS has changed and you can now store FB data as long as the user allows it.
Note: Starting June 30, 2010, all applications will be able to access only a user's public data unless the user grants your application the extended permissions it needs. Read the upgrade guide for details.
/**
* Which permissions can we prompt for?
*
* @TODO - update this list and/or make it customizable.
*/
function fb_permission_map() {
static $perms;
if (!isset($perms)) {
// http://wiki.developers.facebook.com/index.php/Extended_permissions
$perms = array(
// Publishing Permissions
'publish_stream' => 'Allow %application to publish to your stream.',
'create_event' => 'Allow %application to create events on your behalf.',
'rsvp_event' => 'Allow %application to RSVP to events on your behalf',
'sms' => 'Allow %application to send you SMS text messages.',
'offline_access' => 'Grant %application access to your Facebook profile.',
// User Data Permissions
'email' => 'Allow %application to send you email',
'read_stream' => 'Allow %application to display your stream.',
'user_about_me' => 'Allow %application to access your "About Me" section of your profile',
'user_activities' => 'Allow %application access to the users list of activities as the activities connection',
'user_birthday' => 'Allow %application access to the full birthday',
'user_education_history' => 'Allow %application access to education history',
'user_events' => 'Allow %application access to the list of events the user is attending',
'user_groups' => 'Allow %application access to the list of groups the user is a member of',
'user_hometown' => 'Allow %application access to the users hometown',
'user_interests' => 'Allow %application access to the users list of interests',
'user_likes' => 'Allow %application access to the list of all of the pages the user has liked',
'user_location' => 'Allow %application access to the users current location',
'user_notes' => 'Allow %application access to the users notes',
'user_online_presence' => 'Allow %application access to the users online/offline presence',
'user_photo_video_tags' => 'Allow %application access to the photos the user has been tagged in',
'user_photos' => 'Allow %application access to the photos the user has uploaded',
'user_relationships' => 'Allow %application access to the users family and personal relationships and relationship status',
'user_religion_politics' => 'Allow %application access to the users religious and political affiliations',
'user_status' => 'Allow %application access to the users most recent status message',
'user_videos' => 'Allow %application access to the videos the user has uploaded',
'user_website' => 'Allow %application ccess to the users web site URL',
'user_work_histor' => 'Allow %application access to work history',
// Misc Permissions
'create_listing' => 'Allow %application to create marketplace listings on your behalf.',
'photo_upload' => 'Allow %application to upload photos.',
'status_update' => 'Allow %application to set your status.',
);
}
return $perms;
}
This change in the code above adds all the extended fields, and once you have added it you can edit your FB application in drupal .
/admin/build/fb/list then under local settings select edit..
Under fb extended permissions you will now see all the new fields you can check.
Here is where the mystery comes in and hoping someone can help me debug this.
I created a new profile field called user_hometown for example , then on drupal i connected via fb connect with one of my fb test accounts, it created my account and asked me if all of this data can be allowed, i said yes but the user_hometown field never was populated.
anyone have any ideas what are the right profile fields or how this is even supposed to insert data into drupal?
- Forums:

It's not a bug that the
It's not a bug that the profile field is never populated. It's just that there's no code in place to map the data from facebook into profile fields.
You could write a new module that attempts to do this. One approach is to use a hook_form_alter, to pre-populate the fields on the user edit form. You can see fb_user.module (in 3.x branch), it adds user's name and email to the user_register form, if available. In the approach the user would still have to manually submit the form (and would have a chance to edit the values before submitting).
The other approach is to use drupal_execute to automatically submit that same form. This would save the user's profile fields with no action on their part.
This would be relatively simple for your specific case, the user's hometown. It gets more complex if you want to generically support any fields added to a profile.
So sorry was out for
So sorry was out for holidays, looking at fb_user.module now and you have several places where you insert data into the the db for the current {fb_user_app} , I also see when looking at the email area, that you do a few checks if user has authorized this..
So my question would be since we updated fb_permissions.module with all the other extended permissions what actually checks or needs to check if the user has granted permissions for lets say user_hometown..
if ($result && !db_affected_rows()) {
// The row for this user was never inserted, or deleted. Insert now.
$fbu = fb_facebook_user($fb);
if ($fbu) {
$info = fb_users_getInfo(array($fbu), $fb);
$data = $info[0];
$result = db_query("INSERT INTO {fb_user_app} (apikey, fbu, added, session_key, session_key_expires, time_access, uid, proxied_email, time_cron) VALUES ('%s', %d, %d, '%s', %d, %d, %d, '%s', %d)",
$fb_app->apikey, $fbu,
$data['is_app_user'],
$session['session_key'],
$session['expires'],
time(),
$uid,
$data['proxied_email'],
0 // time_cron
);
}
}
so $fbu holds the whole array of data sent back from FB? I see that $info gets sent the first part of the array which is the email..
I just want to know if im digging in the right place I have only had 5 min to quickly look at this but will spend more time, if you can shed some light on what is needed for when permissions are added in the admin, user allows extended permissions and , we do any special checking in the module for this , if all is ok update or insert into database../
thanks ill take a peek into
thanks ill take a peek into those, what if the module pack included a profile system that would add the proper fields to the drupal profile (if you wanted to enable this) then based upon your settings in the admin for the app you could check the ones that you would want populated?
anyone have any thoughts on
anyone have any thoughts on this or wanting to work with this guy, i hit him up a few times seems pretty smart but with out much help from the guys working on the drupal module its kinda a dead zone.. thoughts?