How do I manage a users facebook "managed pages"? - facebook

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"

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 y publish_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:
return Socialite::
with('facebook')
->scopes(['manage_pages', 'publish_pages', 'the_rest_of_your_scopes'])
->redirect();
And to retrieve the user:
$social_user = Socialite::
driver('facebook')
->fields(['accounts', 'some_other_extra_fields'])
->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.

If you check the following Official Laravel Socialite Pacakge
(Use this Package )
https://github.com/laravel/socialite
Facebook providers are there already.
Get the access token from Facebook
Save it to database
Use the graph API of facebook to access page details.
Send the saved access token with api requests
Alternatively you can use this package too.
https://github.com/SammyK/LaravelFacebookSdk

Related

Is there API to get someone's facebook profile with out login to facebook?

I was wondering if its possible to get one's facebook profile (to be exact,'profile url') through their API?
I need an api to get fb profile link using a matching email address. I dont want to login to facebook though.I was trying to search for this but it seems you need to log in to facebook to get that.
Any idea or is it feasible?
You need ID of the concerned user which can't be achieved without using the Facebook Login, since Facebook login is the starting point to get the current user info (/me).
Search API could have helped you since you have the email ids of users, but unfortunately this api doesn't support user search with email!
So, answer is simple- NO, you cannot get the ID (profile link) of the user without using the facebook login.
Not that I can think of. Facebook's Graph API gives you some public info but that info given depends on the users Facebook's settings on what is public or not. You could maybe get some users profile picture but not others, making it not a very viable option for practical use. Hope that helps

How can I detect if a certain post on a Facebook page has been deleted?

I am planning to build a small side project that stores posts from particular public pages. And detect if they delete the post later. Something similar has been done for Twitter. But I couldn't find similar projects for Facebook.
Like this: http://politwoops.sunlightfoundation.com/
But for Twitter. I will do it in Python or C#
How can I go about it?
Any particular code or projects I can learn from?
The only way to check if a post is not there anymore on Facebook is to search for it with a User Access Token of the User who posted it. Every Object on Facebook gets a specific ID, you only have to check if that ID still exists. If not, you get an Error from the API.
For example: https://developers.facebook.com/tools/explorer/?method=GET&path=10203433018378479&version=v2.0
The path parameter is the ID of the Post.
Keep in mind that you need the read_stream permission for that, and you need to let Facebook approve it for other users or it will only work for Admins/Devs of your App. It is not very likely that you will get the permission approved for this though. It usually only gets approved for Apps on "Platforms without a native Facebook experience".
Edit: My bad, i was thinking about User posts, but your question was about Pages. In that case, all you need is an App Access Token (App-ID|App-Secret). The API Call would be the same, you just need to know the Post ID.
About Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens/
http://www.devils-heaven.com/facebook-access-tokens/
For getting the feed of a Facebook Page, see the Facebook docs (including code samples): https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed/
You can use graph api for this. If it's a public page, you can follow these steps:
Create your application in Facebook developers site
Setup the basic graph auth mechanism with your favorite language and get unexpired token.
Use your unexpired access token to do these tasks:
Enter the id of the pages you want to crawl http://graph.facebook.com/[insert page id or url here]/feed
Add post title, postID to your database.
Create a scheduled task on your server to do these tasks:
Select all / page based etc posts on your database and send a request to: http://graph.facebook.com/[insert post ID here]
if it returns it means it's still there. otherwise it will return an error.

Restrict facebook app from accessing user's friends list

I am using facebook to login to my website. The website does not need any information about the facebook user's friends' list. I am interested only in the user's general information.
https://developers.facebook.com/docs/reference/login/public-profile-and-friend-list/ shows the friend list also as the minimum information shared by Facebook.
Hence wanted to check if there is any way to restrict the user friend list information from being passed on from facebook to my application?
No, when a user authorize an application the minimum data shared is it's basic information and friend list.
Unfortunately you cannot change this.
Official documentation:
When someone connects with an app using Facebook Login, the app can
access their public profile and friend list, the pieces of information
that are visible to everyone. Each other piece of information that
someone adds to their Facebook profile is secured behind permissions.
Source: Facebook

How does Amazon ask for so many permissions on Facebook on one screen?

I'm working on a Facebook app that requires a few basic permissions (email, birthday, etc) as well as publish_actions (so I can create stories about user interaction).
When I ask for these permissions, the end user is presented with one screen for the basic permissions and yet another for the publish_actions permission.
However, when I looked at the following app from Amazon:
http://www.amazon.co.uk/gp/socialmedia/promotions/SprngSweep
When I click on the enter button, I am redirected to Facebook to ask for permissions (as expected), however, they have all their permissions one page (Amazon would like to access your public profile, friend list, email address, birthday, photos, videos, personal description, likes and your friends' birthdays and likes. Amazon would like to post on your behalf. Amazon would like to access your data at any time.)
I can't add a picture due to lack of rep
The url that I'm redirect to is this:
https://www.facebook.com/dialog/oauth?client_id=164734381262&redirect_uri=https%3A%2F%2Fwww.amazon.co.uk%2Fgp%2Fsocialmedia%2Ffbr%2Fconnect-handler.html%2Fref%3Dfbr_hn_SprngSweep%3Fie%3DUTF8%26appName%3DAmazon%26externalApp%3DKindle%26onSuccess%3D%252Fgp%252Fsocialmedia%252Fpromotions%252FSprngSweep%253Fie%253DUTF8%2526sm-sweeps_submit%253D1%2526sm-sweeps_submit.x%253D66%2526sm-sweeps_submit.y%253D20%2526sweepsConnect%253D1%2526sweepsEligibility%253D1%26ref%3DSprngSweep%26token%3D6CBF36BD25311891B2F205333EFA3AA78E561AB9&scope=
While attempting to investigate this myself, I noticed that they aren't even passing a value for scope in the url.
How the hell are they doing this?
Most likely they are using an old API (FB changed the behavior over there recently, read their blogs please) or they are using hidden features which FB created for them (as this has an impact on there advertising revenue obviously, and even these guys are "coin operated").
The "two pager" is normal, FB API and FB advertising API quit the same. I wouldn't worry.

Login with facebook and storing important user information

The facebook "wave" has finally hit me and I see that it's now time to integrate the wonders of the Facebook API into my site. I'm a little worried about implementing a "Login with Facebook" button because my site stores information about each user, and I'm not sure whether or not the facebook login system will also store said information. Any user who registers to my site has the ability to "like" certain pages that were found while browsing the site, and the categories of each page the user likes is stored and linked to his username.
If the user were to "login with facebook" however, and thus skip my registration page, would the information about categories still be saved?
Even looking at StackOverflow.com, I notice that all of my profile information etc. is being saved, but where? I used the login with facebook button so where exactly is my profile information being saved?
When you login with Facebook your site gets a Facebook ID and some other information (depending on what you ask for, but normally first name, last name, email address). You can then use the Facebook ID or email address to link it to an existing account in your system. If you can't find it, automatically create a new account with the details provided from Facebook.
You can use the Registration Social Plugin that facebook offer in order to get the data you need from the user while they register to your site using their facebook profile.
Also, as #JonGrant wrote, you can just use the api to get the needed information from facebook, just take into consideration that the more permissions you ask for, the less users will authorize your app.
Edit: Plugin now out of date, please refer to Facebook Login.
This was plugin removed as of API version 2.0. It will stop working
on July 30, 2015. Apps using this plugin should migrate to Facebook Login.
Source: facebook docs