Facebook graph api page post with multiple photos - facebook

I am trying to publish a page post with multiple photos via the Facebook's graph api.
Currently from the docs and another question here it's stated that the photos should be uploaded separately and then publish the post with attached_media parameter.
The photos are uploaded fine without any problem and I get their IDs.
The issue is that the request for publishing the post gives:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "SOME TRACE ID"
}
If I remove the attached_media parameter from the request the post is published fine.. Any Idea what can be the issue?
Specially for CBroe here are the reqiests:
For the photo upload:
endpoint: /{page-id}/photos
payload:
{
"url": "some-image-url",
"caption": "Some image caption",
"published": false
}
endpoint: /{page-id}/feed
payload:
{
"message": "Some post message",
"published": false,
"attached_media": [
{"media_fbid": "PHOTO_ID_RETURNED_FROM_THE_ABOVE_REQUEST"}
]
}
The payload is send as json to the endpoint. This request works only if I remove the attached_media parameter.

TL;DR
Add publish_to_groups permission to the access token and the request for the post should be with parameter published: true. It appears to have a bug in the graph api or lack of information in the official docs.
Details:
Currently in order to publish a page post with multiple photos you will need to:
upload individually the photos and obtain their IDs
use PAGE access token which contains publish_to_groups permission
attach all photo IDs with attached_media[0..N]: {"media_fbid": "PHOTO_ID"}
currently the request for publishing the post fails if it's with parameter published: false, so it needs to be published: true
All of this does not make really sense to me, so I opened a bug report in the developers platform of Facebook. It does not looks right during development of the App to publish live posts to the page...
I'll edit the answer once I have a feedback.

Related

In Instagram Graph API, when I try to publish to Instagram, I receive error 24 subcode 2207006 and cannot publish

For the past 3 months I have been automating posting images to my instagram account. But today it no longer works, I assume because my access token expired. It is just publish that does not work, I can still create the object, which confuses me because the new access token works for some api calls but not all.
My endpoint params for creating an object:
{'caption': 'Filler caption',
'access_token': 'removed',
'image_url': https://www.smashbros.com/assets_v2/img/fighter/mega_man/main.png'}
The object url:
https://graph.facebook.com/v6.0/17841406231094676/media
I import requests for python, then do
data = requests.post( url, endpointParams )
And I get back
{'creation_id': '17900592242391633',
'access_token': 'removed'}
publish Url:
https://graph.facebook.com/v6.0/17841406231094676/media_publish
---- PUBLISHED IMAGE RESPONSE -----
Response:
{
"error": {
"message": "The requested resource does not exist",
"type": "OAuthException",
"code": 24,
"error_subcode": 2207006,
"is_transient": false,
"error_user_title": "Media Not Found",
"error_user_msg": "The media with 17,900,592,242,391,633 cannot be found.",
"fbtrace_id": "AIYNvGl2IQQp5L9G7kb9F7O"
}
}
Does anyone know how I can fix this?
Edit: My script started working again, I believe this was an error on Facebook's end
The issue is that you need 2 different kinds of tokens. A page token to create the media object and then a user token to actually post to Instagram. I'm guessing in your case it worked at first because both tokens were valid, but with time, both expired, but only 1 of them got renewed by your system.
I've been having the same issue, where I could only upload the media object but not publish it until I used a page token to create the media object and then a fresh user token to post it. By doing this I got it to work right away.
I got that solution from here, hope it helps
Media Builder Not Found Exception while Publishing into Instagram using Graph API

Facebook API Lead retrieval for internal business app should i submit for App Review

I am building a dedicated CRM solution and it is supposed to show the list of Facebook leads of the client and then convert manually it to internal lead . I am managed to setup a websocket client and Facebook is sending me lead details including leadgen_id.
{
"object":
"page" ,
"entry": [{
"id": "*****" ,
"time": 1627211279 ,
"changes": [{
"value": {
"form_id": "******" ,
"leadgen_id": "******" ,
"created_time": 1627211277 ,
"page_id": "******"} ,
"field": "leadgen"}
]}
]}
Then i have created an user access_token using Facebook's graph api and requested for the details of the leadgen_id using api endpoint
https://graph.facebook.com/v11.0/<LEADGEN_ID>?access_token=<ACCESS_TOKEN>
I was able to get the details of the test lead I created with the Facebook 's lead testing tool. But when accessing the production leadgen_id I am getting an exception with following as response.
{
"error": {
"message": "Unsupported get request. Object with ID '<LEADGEN_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",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "*********"
}
}
Then I have tried using a system user token and its not even working for the test leads. In some part of documentation it is saying that I need to complete App review to access live data using lead_retrieval and in some other part of documentation its quoted that I don't need app review to use API for internal users . And I don't get the point of creating a 'login with Facebook' for this internal app specific for one user .
Is there anyway other way than completing app review to access lead details using leadgen_id ?
Its turns out I need to complete the app review specifying it as a 'Server to server app' on the review description, which doesn't need any Login with facebook button . Got the idea from https://developers.facebook.com/docs/app-review/resources/sample-submissions/server-to-server/

Facebook Graph API: Unable to reply a comment on unpublish page?

I'm using the Graph API Explorer to reply the comments on fan page via my app.
It works only the page is published. However, it bothers me so much.
How do I to test the app before publishing the page?
What I'm trying to do is the app will listen to the webhook from Facebook and then reply to the comment as long as got a comment.
I've been search for a while, there's very few questions related to this. Any suggestion would be thankful. ;)
// POST
https://graph.facebook.com/{comment-id}/comments
// response when the page is unpublished
{
"error": {
"message": "(#200) Cannot access object_id: {comment-id}",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "{fbtrace_id}"
}
}
Confirmed that you can't access the comments while unpublished as the page id prepends the comment id. I would say quickest and easiest way to test is to just create a separate test page and keep that published.

Facebook Graph API (Post with Photo Ids) - (#10) Application does not have permission for this action

I'm trying to publish a post on my wall with two photos as attachments using Graph API Explorer.
Here's what i did:
I have selected all permissions in my user access token, and am using v2.5.
I have previously uploaded a photo to the endpoint: /me/photo and in response i got its id. i.e. "10154656374686756". This id will remain active for the next 24 hours.
Then I'm passing the photo id as a parameter (that i got in step 2) to my post using endpoint: /me/feed like this:
Graph API Explorer - Post Request
But in response i'm getting the following error instead of the newly created post id:
{
"error": {
"message": "(#10) Application does not have permission for this action",
"type": "OAuthException",
"code": 10,
"fbtrace_id": "BzOCZ1z3tUH"
}
}
I can't figure what i'm doing wrong here. Your help will be much appreciated.

Create a Link Ad for a Facebook object (event url)

In business manager it's possible to create a Link Ad with a Facebook Event url. I like to do the same with Facebook Ads API but facing a permissions error.
The Ad Creative of an Ad created in business manager looks like this one:
{
"object_story_spec": {
"page_id": "24188824589????",
"link_data": {
"link": "https://www.facebook.com/events/25595316793????/",
"message": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"image_hash": "cbb1f226fd5fe47c826dd1cad117????"
}
}
}
When I am trying to create the same Ad Creative via Ads Api I get an error message like the following:
{
"error": {
"message": "Invalid parameter",
"type": "FacebookApiException",
"code": 100,
"error_subcode": 1349118,
"is_transient": false,
"error_user_title": "Disallowed Post Link",
"error_user_msg": "One or more of the given URLs is not allowed by the Stream post URL security app setting. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains. Read https://developers.facebook.com/docs/facebook-login/security/ to learn more about app settings related to security."
}
}
I get the same error if I try to create a Link Post with Graph API separately to use as object_story_id.
We really need this kind of Ads for our business. In stream ads perform much better than display ads. Is there anyway to create ads like this one via Ads API?
You should check the migration settings for your app to see if "Steam post URL security" is enabled.
This prevents URLs being posted by your app which do not link to a domain listed in your app settings.