Posts tagged with facebook-graph-api

I need to upload facebook reels with api but show this error

{ "error": { "message": "(#200) Subject does not have permission to post videos on this target", "type": "OAuthException", "code": 200, "fbtrace_id": "A0vPpH6U1wfZ9o_4cMqmEH3" } }

I have done everything as per documentationall permissions are given eg pages_show_list pages_read_engagement pages_manage_posts

and also i have page admin access (full control )

show some reference image

I am stuck with the Webhook endpoint where I receive the Facebook feeds.

I need to create an API to get the Facebook feeds (comments, like, etc) which are made on my Facebook page.

By following the steps, I have created a facebook app with the developer account. With webhook added

Webhook Added

After that I went to the settings page.

Since I want the feeds, I have select the Page from the dropdown and clicked subscribe. The I need to enter the callback URL.

From my API side, I have created a .NET Core 5 application. Then create a Get and Post method called Webhook. Since I need an https:// connection, I have installed ngRok and setup the test API. And the GET method will return the challenge:

[HttpGet("webhook")] public async Task<IActionResult> Receive([FromQuery(Name = "hub.mode")] string hubMode,                                    [FromQuery(Name = "hub.challenge")] int hubChallenge,                                    [FromQuery(Name = "hub.verify_token")] string hubVerifyToken) {     return Ok(hubChallenge); // this is working... no issue here } 

Back to the Facebook side.

I have added the callback URL after clicking subscribe and got Challenge key in my API Get method. Once its done I need to select the fields i need to subscribe i.e.; feed in order to get the Facebook page response.

Feeds

Then i need to setup permission so, i have subscribed to permission dropdown. Added the callback URL, get the Challenge key and subscription is complete. After that subscribed to pages_manage_metadata , pages_show_list and pages_manage_engagement(although document didn't mention pages_manage_engagement).

After that Went to facebook graph explorer and done the subscription to feed using the page access token https://graph.facebook.com/{page-id}/subscribed_apps?subscribed_fields=feed&access_token={page-access-token}

subscribe to page

This is also done and its says true

I check with the GET method to see whether it is complete and its says feed is in subscribed list Subscribed fields

But after this everything stops :(

When i click the test button its not sending any feed to my Post method in my API.

So i used the graph explore API to comment the Post and post is done , but no webhook response tried comment manually but no response.

So i thought maybe some issue with my API Post endpoint i have created. So i tested with Postman and the request is going through.

I changed by computer to my laptop with different network(you need to try everything possible), still no response.

So Just for the testing i subscribed to the Messaging option in facebook, just to check whether its an issue with the Page. The thing is i got a response to my Post method, so the messaging webhook is sending to the POST method. That means my API end point is correct.

So i thought something to do with by permission, so i enabled all permissions related to the page and tried, but no response.

I changes my facebook account to some other account, not working.

Then i tried with an account with facebook business enabled, no luck

I have tried changing the Permissions in the page, still no luck.

I tryed the gemini,chatgpt 3.5 and 4 ... no luck. asked in the facebook community...that place is kinda dead.

The main issue is i am not even getting any response when i click the Test button. Most of the online issues, they atleast get a hit from test.

So next thing to do is review the app and then test. but when i am in the review page , they are saying we need to test the app well before we go to review. So i an not sure what to do now.

Am i missing something? Any help would be valuable.

I dont know whether its a facebook bug or not. Because some document say

you need if the Page has not disabled the App platform in its App Settings. But in that page there is a turn on button, but it will change its status once we click it, but it will go back to the original state when we refresh the page. App Settings page

If anyone faced this issue and manage to solve this please help. i have been on this for quiet a while and i don't know what to do next.

Thankyou

import requests import pandas as pd import json page_id = "61554487605477" post_id = "122107628540149586" access_token = 'EAAPaIduWx3MBOwj4GBHjpt6xjMRxncIvfCYNNqlWGHDaURhZC1AeDyb3MLjNpz8WbyzyuI84nIVffDxAxnKiyPZA0PvdX45fHQkq0oXz2YI9y41SF1tI2HYDBZAD15CftytfiC9QeBb0dlZCNoDGKvSzf6CAZBnZBBxfHusaFUIeRPtPonZCUV660y0VgNwQFGnVVibWMlJMtZB99G5l5OaiXN1JbD1ySHbZAQowtiMZD' # your access token, from https://developers.facebook.com/tools/explorer/ url = f'https://graph.facebook.com/v16.0/{page_id}_{post_id}/comments?access_token={access_token}' response = requests.request("GET", url) # save name, time, message in excel file data = json.loads(response.text) # create object with only name, time, message print(data) def get_comment_text(comment):     return '{} '.format(comment["message"].replace("\n", " ")) # Create a string containing all comments without newlines text_data = ''.join(map(get_comment_text, data.get('data', []))) print(text_data) # Write the comments to a text file without newlines with open(r'C:\Users\Sanath\Desktop\comments_downloader\kindle.txt', 'w', encoding='utf-8') as text_file:     text_file.write(text_data) # Display success message print('Comments  to kindle.txt') 

i am trying to fetch the comments from my test facebook page by providing post and page id and access token by facebook graph api ...this used to work a few months ago but now after a couple of months when i came back to run the code this is my error message

{'error': {'message': '(#200) Missing Permissions', 'type': 'OAuthException', 'code': 200, 'fbtrace_id': 'AFywRxOtJT1dOeJwznncM48'}} Comments  to kindle.txt 

i want to fetch the comments and stored in a text file called kindle . these are the permissions that i have provided in graph api: pages_manage_cta

pages_manage_instant_articles pages_show_list read_page_mailboxes pages_messaging pages_messaging_subscriptions page_events pages_read_engagement pages_manage_metadata pages_read_user_content pages_manage_ads pages_manage_posts pages_manage_engagement....

even after providing all necessary permission i am recieving a oauthexception i have made sure that post id and page id are accurate and the access token is newly generated one

i have been trying to publish videos on a facebook page's story, but i havent been successful, i have tried using their apis and integrating with restfb as well, As for restfb, i was able to post on a facebook page's timeline, but not on their story, i have included the code showing my implementation using the facebook api and rest fb, thanks for checking out, i appreciate any assistance

public void postVideo(String contentUrl) throws MalformedURLException, FileNotFoundException, FacebookOAuthException {         Users loggedInUser = userService.getCurrentUser();         Socials social = socialsService.getSocialByPlatform(SocialPlatform.FACEBOOK);         UserSocials userSocial= userSocialsService.findUserSocial(loggedInUser, social).orElseThrow(()-> new UserException("User social not found"));         FacebookClient defaultFacebookClient = new DefaultFacebookClient(userSocial.getAccessToken(), Version.LATEST);         File videoFile = new File("uploads/" + contentUrl);         if (!videoFile.exists()) {             throw new FileNotFoundException("Video file not found at specified path.");         }         FileInputStream fileInputStream = new FileInputStream(videoFile); //       Implementation using facebook api //        MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>(); //        requestBody.add("file", new FileSystemResource("uploads/" + contentUrl)); //        HttpHeaders headers = new HttpHeaders(); //        headers.setContentType(MediaType.MULTIPART_FORM_DATA); //        FBVideoStoryStartResponse fbVideoStoryStartResponse = webClient.post() //                .uri("https://graph.facebook.com/v18.0/"+userSocial.getSocialUserId()+"/video_stories", uriBuilder -> uriBuilder //                        .queryParam("upload_phase", "start") //                        .build()) //                .retrieve() //                .bodyToMono(FBVideoStoryStartResponse.class) //                .block(); //        System.out.println(fbVideoStoryStartResponse); //        if(fbVideoStoryStartResponse != null){ //            FBVideoStoryUploadStatus fbVideoStoryUploadStatus = webClient.post() //                    .uri("https://rupload.facebook.com/video-upload/v18.0/" + fbVideoStoryStartResponse.getVideoId()) //                    .headers(httpHeaders -> httpHeaders.addAll(headers)) // Add the headers to the request //                    .bodyValue(requestBody) //                    .retrieve() //                    .bodyToMono(FBVideoStoryUploadStatus.class) //                    .block(); //            System.out.println(fbVideoStoryUploadStatus); //            assert fbVideoStoryUploadStatus != null; //            if(fbVideoStoryUploadStatus.isSuccess()){ //                FBVideoStoryFinishResponse fbVideoStoryFinishResponse = webClient.post() //                        .uri("https://graph.facebook.com/v18.0/"+userSocial.getSocialUserId()+"/video_stories", uriBuilder -> uriBuilder //                                .queryParam("video_id", fbVideoStoryStartResponse.getVideoId()) //                                .queryParam("upload_phase", "finish") //                                .build()) //                        .retrieve() //                        .bodyToMono(FBVideoStoryFinishResponse.class) //                        .block(); //                System.out.println(fbVideoStoryFinishResponse); //            } //        } //      Implementation using restfb         FBVideoStoryStartResponse fbVideoStoryStartResponse1 = defaultFacebookClient.publish(userSocial.getSocialUserId() + "/video_stories", FBVideoStoryStartResponse.class,                 Parameter.with("upload_phase", "start"));         String videoUploadID = fbVideoStoryStartResponse1.getVideoId();         System.out.println(videoUploadID);         GraphResponse graphResponse = defaultFacebookClient.publish(videoUploadID, GraphResponse.class, BinaryAttachment.with(videoFile.getName(), fileInputStream));         GraphResponse graphResponse1 = defaultFacebookClient.publish(userSocial.getSocialUserId() + "/video_stories", GraphResponse.class,                 Parameter.with("video_id", videoUploadID),                  Parameter.with("upload_phase", "finish"),                  Parameter.with("video_state", "PUBLISHED"),                 Parameter.with("description", "A short description text"));             try {                 fileInputStream.close();             } catch (IOException e) {                 throw new RuntimeException(e);             } } 

So using restfb, i get the error "There is a problem uploading your video, Please try again with another file" and i have tried with multiple files below a minute but still the same result.

I'm currently exploring the capabilities of the WhatsApp Business API for a project I'm working on. I'm wondering if the WhatsApp Business API supports sending messages to WhatsApp groups. I've read through the documentation, but I couldn't find a clear answer on this specific feature.

Could someone who has experience with the WhatsApp Business API clarify whether it supports sending messages to WhatsApp groups? If it does, are there any specific limitations or requirements that I should be aware of?

POST = https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages Body = {     "messaging_product": "whatsapp",     "recipient_type": "individual",     "to": "{{Recipient-Phone-Number}}",     "type": "document",     "document": {         "link": "https://test.pdf",         "filename": "Test"     } }