• Great Plugin, been looking for something like this..

    Can you tell me how to pre fill the birthday and mobile phone fields from facebook?

    i have added this to the functions.php file but it doesnt seem to be pulling it in
    add_filter( ‘janrain_gforms_profile_data’, ‘add_birthday_field’ );

    function add_birthday_field( $fields ) {
    $fields[‘birthday’] = array(
    ‘name’ => ‘Birthday’,
    ‘function’ => ‘birthday_field’
    );
    return $fields;
    }

    function birthday_field( $profile ) {
    return $profile->merged_poco->birthday;
    }

    Also this doesn’t seem to be pulling my mobile phone number from my profile

    https://screencast.com/t/Nntf41VCSVl5

    And some of the fields dont get this like the email but the email still works?

    https://screencast.com/t/fw9wGfmW

    Thanks Scott

    https://www.ads-software.com/plugins/rpx/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi, Scott. hope this information below will be helpful to you.

    It looks like your birthday_field() function just needs to be tweaked for Facebook and for that matter any other identity providers you’re using. Each identity provider’s JSON block of data looks a bit different than the others… there’s some degree of normalization of data but we try to keep somewhat consistent with what is returned by each identity provider.

    Within your function, you’ll want to do some IF statements or a single case statement that, based on which identity provider is in play ($profile->ProviderName is it, I believe), looks for birthday in its various locations. For example, for Facebook, there is no merged_poco array… birthday sits right under profile, ($profile->birthday). And of course, some identity providers don’t return a birth date at all, so you’ll want to factor that in.

    You may be running into similar issues with regards to your mobile number and email. It may be the same principle… you just need to point to the right spot in the JSON block, depending on the provider and the location of that data. The best way to find out where everything is located is to go to your Test Widget in the Janrain Dashboard, log in to your various providers in the Test Widget and look at the block of JSON that’s returned. You can also review the permissions settings for each identity provider to see if it’s something that can be returned, but if you need to enable those permissions.

    I hope this helps.

    Thread Starter scott74

    (@scott74)

    Thanks Juanm…. I got this from the dev for the gravity forms janrain plugin…. would you be able to tell me how this should look by repasting the correct version so i can give it a go.

    I really only know html and css and not real good with this stuff but would love to get it working… not sure what you meant by poco or how i should fix..

    add_filter( 'janrain_gforms_profile_data', 'add_more_fields' );
    
        function add_more_fields( $fields ) {
            $fields['birthday'] = array(
                'name' => 'Birthday',
                'function' => 'birthday_field'
            );
            $fields['gender'] = array(
                'name' => 'Gender',
                'function' => 'gender_field'
            );
            return $fields;
        }
    
        function birthday_field( $profile ) {
            return $profile->merged_poco->birthday;
        }
    
        function gender_field( $profile ) {
            return $profile->merged_poco->gender;
        }
    
        function cellphone_number( $profile ) {
            if ( isset( $profile->merged_poco->phoneNumbers ) &&
                    is_array( $profile->merged_poco->phoneNumbers ) ) {
                foreach ( $profile->merged_poco->phoneNumbers as $number ) {
                    if ( in_array( $number->type, array( 'mobile', 'personal', 'cellular') ) )
                        return $number->value;
                }
            }
    
            // Backup. If nothing is set as a mobile or cell number, you might just
            // want to use their default number.
            if ( isset( $profile->profile->phone ) )
                return $profile->profile->phone;
        }
    Thread Starter scott74

    (@scott74)

    By the way here is what came back… I did not see birthday in here, where would i check permissions

    {
      "stat": "ok",
      "profile": {
        "providerName": "Facebook",
        "identifier": "https://www.facebook.com/profile.php?id=1179665512",
        "verifiedEmail": "[email protected]",
        "preferredUsername": "ScottHeliker",
        "displayName": "Scott Heliker",
        "name": {
          "formatted": "Scott Heliker",
          "givenName": "Scott",
          "familyName": "Heliker"
        },
        "email": "[email protected]",
        "url": "https://www.facebook.com/scott.heliker",
        "photo": "https://graph.facebook.com/1179665512/picture?type=large",
        "utcOffset": "-06:00",
        "address": {
          "formatted": "St. Louis",
          "type": "currentLocation"
        },
        "gender": "male",
        "providerSpecifier": "facebook"
      }
    }
    Thread Starter scott74

    (@scott74)

    Ps.. I noticed their birthday api has also a birthday_date for mm/dd/yyyy same format as my gravity form.

    Would this need to be implemented in the function.. How would you do so?

    https://developers.facebook.com/docs/reference/fql/user/

    Scott –

    I have to apologize in advance: I cannot write code for your customization. I am more than happy to provide guidance for you and perhaps even some pseudo code, so that you can take this information and pass it on to someone with WordPress coding experience in your organization and have them write your customization for you, or a contractor who can write PHP code, but I cannot do so.

    As for the guidance promised, if you look at this bit of data returned in the JSON block:

    {
      "stat": "ok",
      "profile": {
        "providerName": "Facebook",

    You’ll see that providerName is Facebook… you would use this in an IF statement in your code to point to the correct location of the birthday field. In your case, you haven’t enabled Birthday as a permission in your app at https://rpxnow.com/relying_parties/changethistoyourEngageappname/providers#facebook but checking that box should return it.

    So in your birthday_field() function, you’d need to write in an IF/else statement that looks at that providerName value and returns the birthday value based on the location:

    function birthday_field( $profile ) {
            if ($profile->providerName == 'Facebook' || $profile->providerName == 'Yahoo!' ) { // Yahoo and Facebook both have birthday in $profile->birthday
                return $profile->birthday;
            }
            elseif ($profile->providerName == 'anotherprovider') { // for another provider, add more elseifs as needed
                return // the birthdate location for that provider
            }
            else {
                return // something else --
            }
        }
    Thread Starter scott74

    (@scott74)

    Thanks Juanm but I dont see anywhere in my account to enable?? I have checked everywhere and the link you provided just takes me to the main app page

    Is there something missing in that url/ part of it looks ?

    https://screencast.com/t/yHMnfUoNUL

    This is my app name if this is what you meant

    https://rpxnow.com/relying_parties/STL-Birthday-Club/

    I’m just not seeing any check boxes to enable anything like birthday..

    Please advise, sorry for the trouble and really appreciate the help

    Thread Starter scott74

    (@scott74)

    Ps…. I am only using Facebook as a login for the form to be populated if that mattters

    Scott –

    Disregard the link I posted… I think it only served to confuse matters. You were supposed to replace changethistoyourEngageappname with your Engage app name and copy and paste the link into a browser, but the forums mangled the URL and cut it off before it was bolded. Since you already posted your Engage name, I’ll just give you the direct link here:

    https://rpxnow.com/relying_parties/stl-birthday-club/providers

    The Facebook permissions page loads first. Find the birthday checkbox there. You can’t miss it. ??

    Thread Starter scott74

    (@scott74)

    Thanks I never would have found that page.. I enabled and ran another test.

    It returned b day this time but in reverse of how gravity forms form fields stores it

    “birthday”: “1974-08-14”,

    MM/DD/YYYY

    I guess maybe why its not pulling it in…. Thanks for your help though I will have to keep trying to figure out

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Birthday and Mobile Phone Facebook’ is closed to new replies.