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 JavaScr开发者_JAVA百科ipt code:
<script>
<!--
Facebook.showPermissionDialog('publish_stream,read_stream');
//-->
</script>
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);
}
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
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/
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.
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();
精彩评论