Webhooks for Lead Ads working but api call to get form values don't - facebook

So, I've created a Webhook with Facebook for my Ads Leads. It is working - I'm receiving the Webhook with the RTUs.
The problem is when I call the api to retrieve the data associated with the form. I'm using the leadgen_id to call the api and I'm gettin:
Unsupported get request. Object with ID '' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
The point is: when I test it here: https://developers.facebook.com/tools/lead-ads-testing the leadgen_id that is returned works with my API calls and I can access the form data that I need.
But when I try with the leadgen_id that I receive from users registering in my ads, it returns the error message.
Any idea of how I can solve this problem?

This sounds like missing 'scopes' on the access token you are using to make the Graph API call. Generally, for webhooks you need a few scopes, these are the ones I currently have on my webhook:
pages_manage_cta, pages_show_list, ads_management, leads_retrieval, pages_read_engagement, pages_manage_metadata, pages_read_user_content, pages_manage_ads, pages_manage_engagement, public_profile
You can use the Access Token Debugger tool to see the list of scopes on your access token (https://developers.facebook.com/tools/debug/accesstoken/)
Your Graph API access token might have expired. To setup a permanent access token follow the instructions on here: Long-lasting FB access-token for server to pull FB page info

I had this same problem. I was able to get this to work by giving my System User 'Manage Page' access and 'Leads Access' in Business Manager.
Add your System User to the Page with 'Manage Page' access.
Business Manager > Business Settings > Accounts > Pages, and select the Page you are working with from the list.
Click 'Add People,' select your System User, and toggle 'Manage Page' setting.
Add your System User to Leads Access.
Business Manager > Business Settings > Integrations > Leads Access, and select the Page you are working with from the list.
Click 'Add People, and select your System User.

Related

To subscribe to the leadgen field, one of these permissions is needed: leads_retrieval

I am integrating facebook leads in my CRM, like I can get leads from Facebook Pages on behalf of my client's.
I am encountering this error.
To subscribe to the leadgen field, one of these permissions is needed: leads_retrieval
I have standard access for 'leads_retrival'. Advanced access can be achieved after hitting the API at least one time.
you need a token that has advanced access to leads_retrival. To get such a token, you can go to the Facebook Graph API Explorer, and then you can add permissions of leads_retrival. Permission can be added in the right middle of the tool and you can add them for testing purposes as you can see in the picture. .
Once you add the permissions, then you can click on generate access token, and a popup will open from Facebook, you have to allow a few things and then you can use that access token for hitting the API for testing purposes. Then you can apply for advanced API access.

facebook leads retrieval issue using graph api

Getting the following error while retrieving leads through graph api using form id. The same end point works fine for other users, but its not working for one of the users of the app. Not sure why its happening. Is there anything related to account type on facebook?
(#10) This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage-pages and https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS for details.
https://graph.facebook.com/v9.0/<form_id>/leads?access_token=<>&appsecret_proof=<>
After adding pages_read_engagement in the scope list and making the user reauthorize the app the said api call is working fine but my query is why did it work for others.
The user does not have any role. User is following oAuth to permit the app to access his facebook pages and ad data

Facebook's Messaging Feature Review API giving permission error for page editors

I have a Facebook page listed in Facebook NPI. I am an editor of that page. When I am trying to check the subscription/news messaging permission status programmatically using this api:
https://developers.facebook.com/docs/messenger-platform/reference/messaging-feature-review-api/?hc_location=ufi
I am getting the following permission error:
(#200) User does not have sufficient administrative permission for this action on this page. If the page business requires Two Factor Authentication, the user also needs to enable Two Factor Authentication.
But when Facebook page owner calls this API, it returns the status successfully.
Can anyone tell me why page editor is getting the permission error?
Guess that is simply considered a page management action you do not have access to using that “role”.
Roles have been replaced by Tasks by now, see https://developers.facebook.com/docs/pages/overview-1#tasks
The only difference in the tasks they can perform, between old Admin and Editor roles, was MANAGE - so I guess you will need to have a page admin approve your user account for that task on the page now first, if you want to be able to use this particular API.

Using Instagram Graph Api with permanent page access token only works for some accounts

I try to fetch some images from an instagram business account through the instagram graph api by means of a permanent page access token (facebook: permanent Page Access Token?). These specific tokens seem to be the only possibility to get permanent access to the graph api for a server-side app.
On the other side I found a hint in the fb documentation that only user accesss tokens can be used to access instagram business accounts.
"Page access tokens are not supported."
https://developers.facebook.com/docs/instagram-api/overview/?locale=en_US
Funny enough I was using page tokens so far without any problems. After resetting the database of my project and generating new tokens I observered that some accounts weren't able to fetch the data while others had no problems.
"Unsupported get request. Object with ID 'XXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation."
I had 2 instagram accounts: 1 was working with page access tokens the other didn't. So, I checked it in the fb graph explorer. Using the user access token I have no problem with both accounts. Using the page access token respectivly for both accounts one is working fine for the query while the other isn't. A third account that I created has the same problem.
Things I tried to resolve the issue:
deleting all permanent page access tokens from my database and generate them again
generate the permanent page access tokens manually by means of the fb graph explorer tool
turn my instagram account back into personal and then again into a business account through the app
turn my instagram account back into personal and then again into a business account through the facebook page
create a new instagram account and a new facebook page to connect (repeating 3. and 4.)
My questions now:
Can I use permanent page access tokens for the instagram graph api?
If not, how do I get permanent server side access to the instagram graph api?
I am now searching the internet and stackoverflow for days and getting crazy because I seem to be the only person experiencing this problem. So, help will be highly appreciated by my fellow developers. Tia.
Since yesterday everything works fine again also when using the permanent page access token. Seems like fb resolved an internal bug. However, the question remains, if page access token can be used in general or if it is just a bug itself.

Long-lasting FB access-token for server to pull FB page info

I'm aware that there are many questions about Facebook access-tokens and the grief they cause, but despite much experimentation and reading many frustratingly vague blog articles (FB and otherwise), I'm still struggling to get a clear answer to my needs. Let me succinctly break down my process so far:
I am creating a site that, server-side, needs to pull the posts/statuses from a single Facebook Page
I am an admin of that Facebook Page
I have created a Facebook App
Using the Facebook Graph API Explorer, I've generated a short-lived key, connected to my app and my account, that grants permission to my account to view the access-tokens for my pages
I've converted my short-lived key to a long-lived key (60 days) ala scenario 4 from this
And here's where I am stuck. My 60 day key works fine for my server to pull the info needed from the page, but as far I can tell, there's no way to programmatically extend that 60 day key. I also do not know of a way to generate a new short-lived key without manually going to the Facebook Graph API Explorer and creating one.
Since it is my server making the requests to the Facebook API and not a user-based system (where I could easily request that a user authorize the Facebook app again), this creates a very clunky system. Since Facebook deprecated offline_access, is there really no permanent way to have my server pull info from my own page? Will I really have to create a new key by hand and manually update my server with it every 60 days?
Or is there something I'm missing?
Update:
The step-by-step guide that was previously found here has been migrated down into its own answer.
These are the steps that were previously in the question - they have been migrated to this answer.
Having found that it is possible to generate a Facebook Page Access Token that does not expire (with help from #Igy), here is a clear, step-by-step quide for all those looking to the same:
Make sure you are the admin of the FB page you wish to pull info from
Create a FB App (should be with the same user account that is the page admin)
Head over to the Facebook Graph API Explorer
On the top right, select the FB App you created from the "Application" drop down list
Click "Get Access Token"
Make sure you add the manage_pages permission
Convert this short-lived access token into a long-lived one by making this Graph API call:
https://graph.facebook.com/oauth/access_token?client_id=<your FB App ID >&client_secret=<your FB App secret>&grant_type=fb_exchange_token&fb_exchange_token=<your short-lived access token>
Grab the new long-lived access token returned back
Make a Graph API call to see your accounts using the new long-lived access token: https://graph.facebook.com/me/accounts?access_token=<your long-lived access token>
Grab the access_token for the page you'll be pulling info from
Lint the token to see that it is set to Expires: Never!
That should do it. You should now have a Facebook Page Access Token that doesn't expire, unless:
You change your Facebook account password
You lose admin access for the target page
You delete or de-authorize your Facebook App
Any of these will cause the access token to become invalid.
If you are getting (#100) Tried accessing nonexisting field (accounts) on node type (Page), go to the Access Token Debugger, copy the value of User ID, and use it to replace the "me" part of the URL in step 9.
This is covered in the Offline Access deprecation document
Use the 60-day token for the page admin to retrieve a Page Access Token (via /PAGE_ID?fields=access_token or /me/accounts) - the Page access token will not have an expiry time
An approach that works in 2019
I was recently trying to achieve something similar (to the use case described in this thread), but I wanted to make sure to respect Facebook's current policies, so I did a little research and here I'm sharing what I found.
My use case
So, as I said already, my use case is very similar to the one described here; that is:
I'm doing some work for a school district.
They are using a software tool to manage pretty much everything that relates to school transportation.
That tool allows them to send email notifications (to subscribers) when they publish bus delay alerts and school closure alerts.
A lot of people in the community follow the organization on their Facebook page, and that's the only place they look for those alerts.
So an employee of the organization has to manually publish each notification on the Facebook page (in addition to creating it in the transportation software). Moreover, those notifications eventually expire (or are simply deleted before they expire), so the employee has to go back later on to delete them manually as well.
It's a waist of time, so what we are trying to do here is to develop as simple system that periodically polls the software tool's database for new (and expired) notifications and update them (i.e. add and remove) on the Facebook page.
This is, in my view, a legitimate use case, but I wasn't sure how to implement it in a way that's in line with Facebook's policies.
The accepted answer
I followed the steps of the accepted answer and it worked, except that things appear to have changed: now, even though the generated page token does not expire, access to data does expire after around 60 days. You will see that as well if you follow the procedure and inspect the page token in the FB Token Debugger Tool.
Besides, the fact that the generated page tokens are tied to the user account is also unfortunate, because if the user updates his/her password, then the page token also gets invalidated.
How to do it in 2019
After several hours of research, I stumbled upon the following Facebook documentation article: Business Login for Direct Businesses.
It turns out that it is now possible, following the steps described in the above article, to generate a page token that is not associated to any particular Facebook user account and which will not expire (unless the FB App gets deleted or the underlying application token gets deleted, you know...)
So here are the steps and the most important parts:
You need a Business Manager account.
Verification will be required and a digital contract will have to be signed.
You need to add the target Facebook page to that account.
You need to create a Facebook App, and transfer that app to the same Business Manager account as well.
The app will have to go through Facebook's review process, because the following permissions will be needed: manage_pages and publish_pages.
Important note For the posts made using the generate page token to be visible to users other than the application administrators, that app will need to have been published and approved.
You may still experiment with the concept without submitting for review, but the posts won't be publicly visible.
In the Business Manager account (only after your app and page have been added to the account), you need to create what's called a System User, and give that user admin role (or permissions) to the target Facebook page.
A system user is owned by the Business Manager account, and isn't tied to a specific user. My current understanding is that one major use case for a system user is programmatic access to Facebook's Graph API (just what we need).
Then, for that system user, you need to generate a access token (which will be never-expiring). You will be prompted to select for which app. You will then select your target app.
You will then need to use the generated app token to generate a page token, which will also be never-expiring. The procedure is described in this article as:
GET /<PAGE_ID>?fields=access_token&access_token=<SYSTEM_USER_ACCESS_TOKEN>
That's it.
That token will never expire, and it won't be tied to a particular Facebook user, so it's exactly what we need!
The last part is to make sure that your Facebook app gets approved by Facebook. It's in fact the most important part, because the whole procedure is worthless if people don't see our posts.
I wanted to know for sure that I could rely on the above procedure to build something for my client without Facebook rejecting it in the end, so, beforehand (i.e. before starting to work on my client's project), I went through the whole process of creating a page, an app, a Business Manager account, etc. I verified my business. I submitted my app for review. In my request, I was very specific about my use case and emphasized that the app was for "self-use" (i.e. that the organization is developing an app for itself, not for other Facebook users). I got approved without less than 24 hours.
A few other notes about the app review process:
I had to select a platform for the app, so I selected website.
I had to indicate why the app needed the two permissions and how it was going to use them.
I had to indicate why the reviewer would not be able to sign into my app and try it (i.e. because the app will be used by a worker process).
For the mandatory screencasts, I simply presented manual operations in the terminal using the curl utility (to generate the page token and make posts to the Facebook page). I also showed how I was using Business Manager to link the system user to the page and generate a token, and so on.
Again, I was very specific about my use case, and I think that that helped.
I hope this information will be useful to people with similar use cases.
Many thanks to #redhotvengeance for step-by-step guide.
After some time, now there is clearly described in Facebook documentation:
https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension
Extending Page Access Tokens
Apps can retrieve a page access token from Page admin users when they
authenticate with the manage_pages permission. If the user access
token used to retrieve this page access token is short-lived, the page
access token will also be short-lived.
To get a longer-lived page access token, exchange the User access
token for a long-lived one, as above, and then request the Page access
token. The resulting page access token will not have any expiry time.
You can also copy and past from the app dashboard on facebook.
The steps:
Go to https://developers.facebook.com
Select your app in the top right corner of the page
(pic of what it looks like)
Click on Messenger from the options on the left (it will go to setting automatically) (pic of what it looks like)
Go to the "Token Generation" section in the page. Select what page you want to generate the token for. (pic of what that section looks like)
The copy and past your page token where ever you need it.
Keep in mind that while in theory your token won't expire, that it is directly tied to what ever facebook account your logged into. So say you change your password or you remove the permissions from between your account and your app then your token won't be valid any more.