2021 Fillmore Street #1128

}

24/7 solutions

Top 10 Cloud Providers

Dynamic Facebook Permissions for your Facebook App

What are Dynamic Facebook Permissions? Let’s say you’ve written a Facebook App using the Facebook JavaScript API, and you don’t want to ask for a ton of permissions when the user signs up for your Facebook App because you’re afraid the permissions will scare them away. No worries. What you can do is in JavaScript […]

What are Dynamic Facebook Permissions? Let’s say you’ve written a Facebook App using the Facebook JavaScript API, and you don’t want to ask for a ton of permissions when the user signs up for your Facebook App because you’re afraid the permissions will scare them away.
No worries.
What you can do is in JavaScript land ask for permissions when you need them.
How do you do this?
First, you’d define a handy dandy little JavaScript object to ask for permissions. I’m using ExtJs so I use Ext.define to define the object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Ext.define('Common.FacebookSecurity',
{
    statics:
    {
         /** All functions here assume facebook api is already loaded */
         validatePermissions: function(permissions,FBObject,callbackFunction,scope,returnOnly)
         {
            FBObject.api('/me/permissions',function(response)
            {
                var values = response.data[fusion_builder_container hundred_percent="yes" overflow="visible"][fusion_builder_row][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"][0];
                /** Some invocations may want to get the permissions results*/
                if(returnOnly)
                {
                    callbackFunction.call(scope,values);
                    return true;
                }
                var compPerms = "";
                for(var i = 0; i < permissions.length; i++)
                {
                    if(values;
                    }
                }
                if(compPerms == "")
                {
                    callbackFunction.call(scope);
                    return true;
                }
                Common.FacebookSecurity.askPermission(compPerms,FBObject,callbackFunction,scope);
                return true;
            });
        },
        askPermission: function(permission,FBObject,callbackFunction,scope)
        {
            FBObject.ui(
            {
                method:"permissions.request",
                perms: permission
            },
            function(response)
            {
                if(response.perms == permission)
                {
                    callbackFunction.call(scope);
                }
                else
                {
                    Ext.Msg.alert("Warning! Some of the actions you selected cannot be performed without the permissions required by facebook");
                }
                return true;
            });
            return true;
        }
    }
});

After you define the FacebookSecurity object, you’re now able to ask for permissions on demand.
Let’s say that I want permission to the user_photos before I show the end user an album of their photos. I’d just wrap my code to show the album with the FacebookSecurity.validatePermissions call.

1
2
3
4
5
6
Common.FacebookSecurity.validatePermissions(,
    FB,function()
    {
        this.win.viewAlbums();
    }
 ,this);

If we don’t have permissions to see the user_photos or publish_stream, then we will invoke Facebook to prompt to grant access. If the user doesn’t grant access, then we don’t show the album.
Easy Enough?[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

Joel Garcia
Joel Garcia

Joel Garcia has been building AllCode since 2015. He’s an innovative, hands-on executive with a proven record of designing, developing, and operating Software-as-a-Service (SaaS), mobile, and desktop solutions. Joel has expertise in HealthTech, VoIP, and cloud-based solutions. Joel has experience scaling multiple start-ups for successful exits to IMS Health and Golden Gate Capital, as well as working at mature, industry-leading software companies. He’s held executive engineering positions in San Francisco at TidalWave, LittleCast, Self Health Network, LiveVox acquired by Golden Gate Capital, and Med-Vantage acquired by IMS Health.

Related Articles

What is Tigera?

What is Tigera?

An AWS Advanced Technology Partner, Tigera delivers Calico and Calico Enterprise for security and networking on EKS, both of which are AWS Containers Competency certified.

AllCode AWS Analytics Services

AllCode AWS Analytics Services

AWS Analytics ServicesAWS AthenaS3-based query data using SQLAWS CloudsearchManaged Search ServiceAWS ElasticsearchStreamline Elasticsearch...

Free AWS Services List

Download this FREE list of all 200+ AWS services and ensure that you're using the optimal services for your use case to enhance efficiency and save money!

Free AWS Business Continuity Plan Template

Make sure you have the proper business continuity plan explicitly for you AWS infrastructure. our professionals built this template using AWS best practices so you can ensure it's built to scale! 

Free Cloud Migration Checklist

Without the proper cloud migration strategy, you risk losing time and money. Ensure that your migration process is running smoothly with our FREE cloud migration checklist.

Free AWS Services List

You might be optimizing with the wrong AWS services. Download this FREE list of all 200+ AWS services and ensure that you're using the optimal services for your use case to enhance efficiency and save money!

Download your FREE AWS Business Continuity Plan Template
Download Free 200+ AWS Services Checklist
Download our 10-Step Cloud Migration ChecklistYou'll get direct access to our full-length guide on Google Docs. From here, you will be able to make a copy, download the content, and share it with your team.