Running a Startup on AWS? Get Funding With AWS JumpStart. Click Here to Learn More

2021 Fillmore Street #1128

}

24/7 solutions

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

Here’s Why You Should Work with an AWS Partner

Here’s Why You Should Work with an AWS Partner

Amazon Web Services is understandably a difficult platform to adapt to and utilize fully upon first getting started. Some organizations can be selected to become certified partners to indirectly extend services to help build on the Amazon Cloud. Finding a certified company to help build out is undoubtedly the best way to significantly simplify, streamline, and reduce the cost of utilizing AWS.

Amazon Web Services – CodeCatalyst

Amazon Web Services – CodeCatalyst

When a development team is building out an application, it helps to have access to the same resources, have the tools for planning and testing, and to have access to the application all in one place. CodeCatalyst comes with a slew of continuous integration/continuous development (CI/CD) tools and can leverage other AWS services and be connected to other AWS projects on an account. As a collaborative tool, it is easy to introduce new members into the project and to log all activity or all tests from a single dashboard. It’s a complete package of all the tools needed to securely work on every step of an application’s lifecycle.

The Definitive Guide to AWS Pricing

The Definitive Guide to AWS Pricing

Perhaps the biggest issue with AWS that its competitors edge out on is the confusing pricing model. It does promise the capacity to help users save significantly on funds that otherwise by avoiding spending on unnecessary resources, but getting to that point isn’t always clear. We will be covering in greater detail how this works.

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.