Issue with commenting on Facebook posts with api - python-3.x

I'm a beginner on Facebook API but after reading up and understanding whatever I could I'm still stuck because I can't find any good documentation that is not outdated.
I'm trying to comment on my own post and I keep getting this error:
Publishing comments through the API is only available for page access tokens
I do understand that I require a page access token for the latest version of the API but even after getting the page access token I'm still facing this issue.
Here is a screenshot of my graph API explorer
Here I first clicked on get user access token and gave it all possible permissions. After that I clicked on get page access token and then tried to post the comment.
Note: The post was made by my ID and is visible only to me, I am sure that the user ID and post ID is correct because I am able to view its details
I also tried it using python with the token ID above and this code.
import facebook
graph = facebook.GraphAPI(access_token=token_id)
#This does give me the post details
#print (graph.get_object(id = my_id +'_10214865328931217'))
graph.put_object(parent_object=my_id+'_10214865328931217',connection_name='comments', message='Test')
But I still get the same error. Seems like there is something about the way page access tokens work that I do not understand.

Related

invalid/missing permissions trying to read leadgen data in webhook Facebook Graph API

I use the version 9.0 of the Grapph API. The leads retrieval was wroking ok, but the last 3 weeks I am not able to retrieve lead form information, using the endpoint :
https://graph.facebook.com/v9.0/${leadId}/?access_token=${process.env.FACEBOOK_PAGE_ACCESS_TOKEN}
The page access token as well as the facebook app has all the permissions like leads_retrieval, pages_manage_ads, pages_manage_metadata, pages_read_engagement, business_management, public_profile, pages_show_list.
When I create a lead form id from the page that is connected to the app, and then use the testing tool (https://developers.facebook.com/tools/lead-ads-testing) to check if the webhook works, everything works ok !!
The facebook and the connected page that are connected and were used for testing purposes, do belong in different businesses.
The problem is that when someone submits a lead from paid campaigs, then the following error message shows:
An invalid response was received from the Facebook API: {"error":{"message":"Unsupported get request. Object with ID '1223289864932223' 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","type":"GraphMethodException","code":100,"error_subcode":33,"fbtrace_id":"AIQ5Q-yJo249IZwdn10dfhi"}}
Is there an error in the set up of the whole system? Something that needs to be changed? Why suddenly did it stop working ?

Instagram access token with invalid error

How can I display Instagram images of my account to my website homepage using access token and user id?
I followed this guide and get Instagram access token and user id https://developers.facebook.com/docs/instagram-basic-display-api/getting-started
With this guide I get my long-lived access token
but when I run below code in PHP
$access_token="--elided--";
$photo_count=6;
$json_link="https://api.instagram.com/v1/users/self/media/recent/?";
$json_link.="access_token={$access_token}&count={$photo_count}";
echo json_link;
It shows:
{"meta": {"code": 400, "error_type": "OAuthAccessTokenException", "error_message": "The access_token provided is invalid."}}
How can I show Instagram media on my website?
That guide didn't work for me either. Eventually, I figured this out following the procedure described here.
A few key points to keep in mind:
Tokens are being generated from Facebook for Developers
, with no need for a post request like before.
To fetch the photos, you need to make more than one call to the API: One for fetching the photos' IDs and then, one separate call for each ID to get the actual data (permalink, image URL, caption, etc).
There is a limit to the calls that you can make per hour, which, as I realized, can be easily reached on a site with moderate traffic. So, you need to somehow cache the results (on WordPress, I used a transient for that, which seems to work fine).
The token expires after 60 days and you need to refresh it on time for your app to keep working.
Im kind of late but perhabs try to use different API URL. I was also stuck on this problem, trying to use
https://api.instagram.com/v1/users/self/media/recent/?...
But later found this address
https://graph.instagram.com/me/media?fields=media_url,media_type&access_token=...
It works for me with this URL. Other stuff to put into fields=
I would reccomend testing with either curl in cmd or downloading Postman
Also if you followed that guide, you'll end up with short-lived token. There is a way to exchange it for long-lived token in this tutorial
But all you really need to do is get the URL ready
https://graph.instagram.com/access_token?grant_type=ig_exchange_token&
client_secret={client_secret}&
access_token={token}
where
client_secret is your instagram secret (developers.facebook.com => my apps => => on the left panel click "Instagram basic display")
token is that short-lived token you get from the tutorial mentioned in question (this one)

facebook Page Access Tokens to get user profile

First time touching things about facebook.
Trying to do facebook 3rd provider login.
The developer I worked with is doing it through back end instead of how facebook's tutorial is doing it through frontend.
Right now the login works and able to get the return of
accessToken: "EAAaz15rigu"
userID: "10928"
Now trying to get the user profile such as first, last name and avatar.
I searched around and found this documentation
https://developers.facebook.com/docs/messenger-platform/identity/user-profile/#fields
https://graph.facebook.com/<PSID>?fields=first_name,last_name,profile_pic&access_token=<PAGE_ACCESS_TOKEN>
The thing is, there isn't <PSID>Page Scope ID and <PAGE_ACCESS_TOKEN> provided
So again, I searched for page access token
https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
https://graph.facebook.com/{your-user-id}/accounts?access_token={user-access-token}
this is what I see so I entered what is returned from login https://graph.facebook.com/10928/accounts?access_token=EAAaz15rigu
What I see is an empty array though, even if the array is not empty as show in the sample in the documentation. I still don't see anything that is <PSID> that I can use from my backend to get user profile.
Can someone please give me a hand to walk through this?
Thanks in advance for any help / suggestions.

Instagram server side authentication 2019

I just can't get it right.
There are docs for instagram api that says do one call, it will redirect user to a page where he authenticate, then you get code from Redirect Url and now using this code you can get token. That is working and it is just fine. But, what if i want to do a website for myself as personal page and show my own instagram photos filtered by tag to ANYONE. I don't need OAuth, any login. I'm ok with creating Node server and make a call smth like this:
http://api.instagram.com/auth?client_id_or_login=vvinog&password=secretpassword
and get token from this call. But it looks like in the internet no one do this, or i dump?
Can you please advice some tutorial, approach that allows me to do that?
Any code snippets are super welcome.

Facebook Graph API permission issue

I have a problem with querying the Facebook Graph API and reading with extended permissions. I want to query a page's latest posts with additional data for a reporting dashboard (show the number of likes, reactions and post impressions) I have an express app with passport-facebook running in order for the user to authenticate and provide the permissions in question. This setup used to work before, but now I am experiencing a strange problem.
This is what I am requesting: created_time,link,full_picture,message_tags,with_tags{link},message,reactions.summary(true),insights.metric(post_impressions)
I had my app in Facebook's review process and they granted me the read_insights permission for querying insights.metric(post_impressions). After the review I was able to pull all the data I needed from the API. That was 2 weeks ago. Today I experienced the problem that I can only pull very limited data out of the API. The response keeps giving me Permission error (OAuthException), stating "User doesn't have enough permissions to load insights", "You do not have enough permission to view the metric."
However, when I add the limit and/or the after params to the query I do get data back, but only with very low values for limit (that is <= 5, but after 2 paginated requests, no subsequent requests are allowed) or a value for after, which I don't have for an inital request.
Has there been a change to the API (couldn't find anything in the changelog)? Maybe I'm just overlooking something trivial?
Thanks!
Since nobody else (not here or anywhere else I asked for help) seemed to have experienced the issue I filed a bug at Facebook and it turned out to be an individual problem with some item(s) on my page's feed. Here's their response:
This is a particular issue with one or more specific posts from that page feed, that is causing the entire call to fail when trying to include it.
This issue might be addressed in a future version of Graph API. There are two workarounds for now: either use a page access token or if sticking with a user access token, giving it granular permissions to the pages.
I've tried option 1 and a page access token seems to fix the issue.

Resources