One of the projects I’m currently working on needs has a large chunk of Facebook integration. It’s thrown up a couple of problems around groups and group permissions:
the need to figure out which groups a user belongs to
which of those groups the user has “write” permissions for.
The Facebook API is a bit of a moving target with all the various updates and changes going on, and documentation is a bit sparse. The first part of the challenge is relatively straight-forward, but the second is a bit trickier.
After much fiddling around, I knocked together two functions - one which retrieves data from the Graph API via a generic API url and cleans up the JSON object that gets returned; and a second that checks which groups the user can write to.
This second function requires that a Facebook API object has been created, as per the PHP SDK:
The existence or otherwise of $me can then be used to check if there’s a valid session before calling any functions that need an established session to prevent blow ups.