Fahim Akhter
Fahim Akhter

Reputation: 1625

Facebook permissions: How to check if the user has already allowed publish_stream for your application

How do I check if the user has already allowed your application to publish on his stream (to avoid the momentarily popup menu). Currently I'm simply using this JavaScript code:

<script>
    <!--
        Facebook.showPermissionDialog('publish_stream,read_stream');
    //-->
</script>

Upvotes: 2

Views: 18208

Answers (5)

blackjack
blackjack

Reputation: 101

Using FB sdk, you can simple use the "/me" endpoint to check for specific permission status. For all the permission, make the permBundle to be null, permission status for all is returned in the response.

final Bundle permBundle = new Bundle();
permBundle.putCharSequence("permission", "publish_actions");
GraphRequest request = new GraphRequest(
        AccessToken.getCurrentAccessToken(),
        "/me/permissions", permBundle, HttpMethod.GET,
        new GraphRequest.Callback() {
            @Override
            public void onCompleted(GraphResponse graphResponse) {
                Log.d(TAG, "response: " + graphResponse.getJSONObject());
            }
        }
);
request.executeAsync();

Upvotes: 0

dain
dain

Reputation: 6699

The right way to do this with the Graph API is to use User.permissions.

See: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fpermissions

So with the JS SDK you can do:

FB.api('/me/permissions', checkAppUserPermissions);

function checkAppUserPermissions(response) {
    console.log("User permissions response", response);
}

Upvotes: 14

josh
josh

Reputation: 9538

Building off AdamB's answer, if you're using the JavaScript Graph SDK, you can still make calls to the REST API (the function users.hasAppPermission is part of the REST API).

Go to FB.api for instructions.

Upvotes: 0

Pons
Pons

Reputation: 1776

abronte is right, use hasAppPermission, as you can see in this tuorial:

http://www.barattalo.it/2010/01/17/posting-to-facebook-from-website-with-facebook-connect/

Upvotes: 0

AdamB
AdamB

Reputation: 3121

Use Users.hasAppPermission to check if a user has those permissions.

General API: http://wiki.developers.facebook.com/index.php/Users.hasAppPermission

Javascript library: http://developers.facebook.com/docs/?u=facebook.jslib.FB.ApiClient.users_hasAppPermission

Upvotes: 3

Related Questions