Facebook Messenger - add pages to my facebook app - facebook

I'm developing app which allows me to chat with customers via messenger. I'm chatting as a Page. I had to add that page into Facebook app -> Messenger -> Settings -> Access Token. It all works fine but is there any way to make that via API? I wanna add more pages on which I'm not admin. In fact I wanna allow admins to add theirs pages using my app.

Yes you can do that and this is the process
1: First thing first you will make a facebook login button with this scope pages_show_list when user clicks on it he/she can select as many page as he want, after the login flow completed you should have a App-Scoped User Access Token
2: since you had the pages_show_list scope when user signed in you now have the ability to call to this endpoint using the user access token graph.facebook.com/me/accounts?fields=name,access_token&access_token=[USER ACCESS TOKEN] after requesting for this endpoint you will get a list of the pages that the user was selecting in the login flow and you now will see that in the response you have name and access_token for each page
3: grab an access token of the page you want and post to this endpoint graph.facebook.com/{page-id}/subscribed_apps?subscribed_fields=feed,[and any other fields you want to subscribe to]&access_token=[USE THE PAGE ACCESS TOKEN]
after that you should get a success response and now your app is subscribed to the Facebook page

Related

How can I login to Facebook from my background job?

I want to regularly post updates to my company's Facebook page using a timer task. In order to post to a facebook page I need to obtain a user (page) access token. In order to obtain a user access token I need to login to Facebook on behalf of a user.
How can I login to Facebook programmatically with some user's email and password from a background job without clicking on any UI?
You cannot programmatically get an user access token through Facebook Graph API. User access token could only be retrieved by login flow.
In your situation, you can consider using an extended (long-lived) access token.

Posting to a Facebook Page Wall from a Web Server

I've been reading documentation and Stack Overflow link all morning, but I'm just not understanding the correct process to authorize a web server to post to a Facebook page wall.
What I'm not clear on is why I have to post to Facebook as a Facebook User, using an access_token, meaning that this user has to log into Facebook manually to authorize my app.
I'm not trying to authorize a User, nor any of my visitors to do anything with their accounts, so I don't need any permissions from them. Instead, I'm trying to authorize my Web Server to post updates to its wall as a specific Page.
Why do I have to use a user access_token to do this? I'm not attempting to impersonate the user, I'm trying to post to the page as the page...
Is it possible to authorize a user and get their access token without having to create a login page on the Web Server? I don't want to have to require the user to login to make this work, I thought that was the point of having an app ID and Secret?
I guess my question is this: Is it not possible to allow a web server to post to a Facebook page wall as that page, without having to present a login dialog to a specific user? If it is possible, what is the correct workflow to set this up?
In order to post to a Page as a Page, you have to use a Page Access Token. You get that with a User Access Token, and you can extend it so it will stay valid forever.
Steps:
Request a User Access Token with the manage_pages permission (valid for up to 2 hours)
Extend the User Access Token (valid for up to 60 days)
Get the Extended Page Access Token for your Page with the User Session
Store and User The Page Access Token in the publish call
It may sound a bit complicated, but there are many tutorials for this and you donĀ“t actually need to program it, you can just use the Graph API Explorer.
Here are some Links about the Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens/
http://www.devils-heaven.com/facebook-access-tokens/ (see "Extended Page Access Token" for a step by step tutorial)

Facebook API Integration

I want to avoid second login on my web-application. I want from my users who want to signup in my web application, then he/she login from facebook account and installed my facebook application, application ask for some permissions Full Name, Contact list, Primary Email, Chat, Messages. now my web-application linked on his facebook account. after then he/she logout from facebook the facebook session is destroyed and browser is closed
when he/she wants to login after 1,2 days. I don't want that user login again from facebook because he/she already logged before and our application is already linked on his account.Is this is possible.
when he/she wants to login in my application so he/she can access chat/message and friendlist from facebook.
You should be able to use your app's access_token to make Facebook requests to publish graph requests but I don't think you can do everything you want. You need the user access token
https://developers.facebook.com/docs/facebook-login/access-tokens/

Facebook Page update through external page

I'm new to Facebook App development and I got this Problem:
I've created a Facebook Page (so I'm the administrator). Now I would like to have an external Webpage with a simple textarea and a "send" button. So everybody who has the link to this page could update this Facebook Page even without a Facebook account. This status update should be send by my page administrator account.
I thought I could write an app and authorize this app to publish_streams on the page and after the authorization I could switch $fbuser = $facebook->getUser(); to $fbuser = IDOFMYACCOUNT.
So the fbuser would be always my account wich is allowed to post to the Page.
If I try to use this application with an other browser (wich isn't logged in to my fb account) I get this error: (#200) The user hasn't authorized the application to perform this action
So this is the way I thought I could solve my problem.
Do you guys have an idea how I (and other people who don't have a FB account or don't wan't to login or I don't want to add them to Facebook Page administrator) could update the Facebook Status of a Page from an external website?
You will need your token "baked in" to your code and some sort of admin back end to update the access token before it expires.
Also you need manage_pages permission and the token of the page if you want to post as the page.
This can be accessed from /me/accounts

How to use Facebook API to publish an event on a page after logging-in a user?

I used the graph api in order to connect the user and publish an event on its wall.
But if I am connected as a page, I get this error message : "You need to be connected as a user and not as a page to run this app"
But I which I could publish my event on a fan page.
Here is my TOKEN_URL
How shoud I do to be able to publish on my fan page.
How can I enable that ?
To publish "on behalf" of a Page, you need to use a Page access token. To get a Page access token, first get an access token for a user with the manage_pages and publish_stream permissions:
https://graph.facebook.com/oauth/authorize?client_id=YOUR_APP_ID&
redirect_uri=YOUR_REDIRECT&scope=manage_pages,publish_stream&type=user_agent
Then, using the access token you get as a result, do a GET of:
https://graph.facebook.com/me/accounts?access_token=ACCESS_TOKEN_FROM_STEP_1
Here, you'll find the list of the Pages the user is an admin of. Here you can grab the access token for one of these Pages. Now calls you make will be made on behalf of the Page. Now anything you try to post will be posted as the Page. If you are trying to create events, you may also need the create_event permission.
To see how this works, you can test this out using these URLs in your browser or in the Graph API Explorer.
You need to get an offline access token with the manage_pages permission for the user that created/owns the fan page. After obtaining the user's access token, then you need to get the page's access token.
See this answer with code for details:
How can I use 'manage_pages' permission with the SDK on Facebook?
You could log in as the administrator of the page and create an offline access token for that user.