I am currently working on a project where we want to post to a users facebook wall or the wall of one of a users managed pages.
See this page: https://socialiteproviders.github.io/
Note that facebook is not listed! Weird being it is one of the top social networks, why is it left to be a custom, override provider?
return Socialite::with('facebook')->scopes(['publish_actions', 'manage_pages', 'pages_show_list'])->redirect();
and then
$user = Socialite::driver('facebook')->user();
Where can I find documentation on socialite in regards to facebook? Specifically how do you get the information on managed pages for the user who just logged in.
We do have app permission from facebook. When you link your account, on the facebook page it pops up asking to give permission to the app to manage pages.
When I dd() the results of ->user()
I get
token, refreshToken, expiresIn, id, nickname, name, email, avatar, user -> [name, email, gender, verified, link, id], avatar_original, profileUrl.
If I understand correctly, there should be a way to get a “data” attribute that contains information on managed pages.
see this link: https://developers.facebook.com/docs/pages/access-tokens#multiple-pages
Am I going to have to work directly with the Facebook API, or is there a way to get this information out of socialite?
Thanks!
EDIT:
I was asking additionally about a facebook provider, and whether it was hard coded into socialite. I have since posting this foind in vendor/laravel/socialite/SocialliteServiceProvider.php is actually wired up for facebook. I still however, cannot figure out how to manage a facebook users “managed pages”
2
Answers
If you check the following Official Laravel Socialite Pacakge
(Use this Package )
Facebook providers are there already.
Alternatively you can use this package too.
You are close, in my opinion.
As you can see in the Facebook API Documentation, to give your application the ability to publish in a page that the user manages, you need to ask for
manage_pages
ypublish_pages
permissions.On the other hand, by default Socialite will ask Facebook for the most common fields (like
id
,email
,name
, etc) but to get extra -driver specific- fields you need to specify them too. So this should do it:And to retrieve the user:
Disclaimer: I haven’t test it yet, but this should include an
accounts
key in the user object that will have an array of the user page(s), his/her role(s), page info and the token to perform actions in the page (yes, like publish).I hope this can serve you as a guide at least. Good luck.