Posts tagged with facebook-graph-api

I'm trying to extract a month worth of facebook posts into a csv file. I'm extracting from the 1st May until 30th May of 2024, but once my script done running, it only extracted posts from the 30th May 2024 (it started on this date) until 12th May 2024.

It doesn't extract from the 9th May until 1st May 2024.

Below is my code:

import pyfacebook from datetime import datetime, timedelta, timezone import json import pandas as pd import time # Initialize Facebook Graph API connection (replace placeholders with your actual credentials) graph = pyfacebook.GraphAPI(access_token='my-access-token', version='v20.0') # Define the page ID page_id = 'my-page-id' # date from_date = '2024-05-01' to_date = '2024-05-30' # Construct the API request URL (notice the parameters 'since', 'until' and 'fields') posts_url = f'/{page_id}/feed?fields=attachments,created_time&since={from_date}T08:00:00&until={to_date}T23:59:59' posts_data = graph._request(posts_url).json() while True:      if 'paging' in posts_data and 'next' in posts_data['paging']:         posts_url = posts_data['paging']['next']         posts_data = graph._request(posts_url).json()         time.sleep(2)  # Increased delay to be safe     else:         break  # No more pages to retrieve      df = pd.DataFrame(posts_data) df.to_csv('facebook_data.csv', index=False) 

Here is the result, it ends on the 9th May 2024 instead of continuing until 1st May 2024:

How do I extract the full month's worth of data?

I've recently encountered an issue with a Facebook app (A php scriot) I've developed, and I'm seeking advice on how to troubleshoot it effectively. Here's the situation:

I've created a php script using the Graph API Explorer in Facebook Developer account, which automatically posts content to a Facebook page. While the app works perfectly fine when I'm logged into my admin account, I've noticed that the posts made by the app are not visible when I log out.

My facebook app mode is still in development mode. Could it be the reason?

I've checked the privacy settings of the posts, and they're set to "Public." Additionally, I've ensured that the app has the necessary permissions, including pages_manage_posts and pages_read_engagement. However, despite these precautions, the posts remain invisible to users who are not logged into an admin account.

I'm trying to change a campaign status using the Facebook Marketing API as documented here.

I managed to change the campaign status to PAUSED, but I can't change it back to ACTIVE, even though the API response indicates success.

Here is the API request I'm making:

https://graph.facebook.com/v19.0/{campaign_id}?access_token={token}&status=ACTIVE

The response I get is:

{   "success": true } 

However, the campaign status remains paused. Has anyone encountered this issue or know why the status isn't updating despite the success response?

Additional details:

  • I used the same approach to pause the campaign, and it worked perfectly.

  • The access token and campaign ID are correct.

Any help would be greatly appreciated!

I am trying to change the status of a Facebook campaign using their Marketing API as documented here. However, I keep encountering the following error:

{     "error": {         "message": "Unknown path components: /<campaignId>",         "type": "OAuthException",         "code": 2500,         "fbtrace_id": "AZruauHBbtO4IzLuRmF90c-"     } } 

Here is the full API request I'm making:

https://graph.facebook.com/v19.0/act_<accountId>/campaigns/<campaignId>?access_token=<token>&status=PAUSED 

I've tried double-checking my IDs and access token, and they are correct.

Can anyone help me understand what might be going wrong and how to fix this error?

What I've tried:

  • Verifying that the campaign ID and access token are correct.

  • Checking if the endpoint and parameters are correctly formatted.

According to Facebook Graph API, I need the postId or the objectId to fetch the comments on the specific post, but upon visiting the post, the url gives a hashed parameters so I am unable to get the postId.

BUT if the post contains a photo, I can click on that photo and get its Id, then I can get the comment but for that photo only not on the post itself.

So how can I get the postId when Facebook only gives a hashed value when vieweing the post?