Posts tagged with facebook-graph-api

How can I post via API to a Facebook Page without having my "Facebook App" suspended/deleted?

I need to share a URLs per day, via API, from my own script to a Facebook Page I manage.

I followed these instructions to create a "Facebook app" and get the "never-expiring" token.

Once I have the token, I can easily post like this:

<?php class FacebookMessenger{     protected string $pageId = '<my-page-id>';     protected string $token  = '<my-token>';     public function sendUrlToPage(string $url){         $endpoint = "https://graph.facebook.com/v19.0/{$this->pageId}/feed";         $this->lastResponse =             HttpClient::create()->request('POST', $endpoint, [                 "headers" => [                     "Content-Type" => "application/json",                 ],                 "query" => [                     "link"          => $url,                     "access_token"  => $this->token                 ]             ]);         $content = $this->lastResponse->getContent(false);         var_dump($content);         die();     } } (new FacebookMessenger())->sendUrlToPage('https://example.com'); 

This works beautiful for a few days, but then the Facebook App I created gets "restricted":

TLI Sharer App DEV is restricted due to violations

The app TLI Sharer App DEV is in violation of Meta’s Platform Terms or Developer Policies and has been restricted, as described below: Platform Term 7.e.i.2 - Negatively impacting platform, products, data, or users

We determined that your app is negatively impacting the platform, products, data, or users and has violated or may have violated our terms. This violates Platform Term 7.e.i.2.

This is the linked page: https://developers.facebook.com/terms/dfc_platform_terms/#compliancereviewrightsandsuspensionandterminationoftheseterms

I fail to see how running 5/6 API requests like this is a problem, and I have absolutely ZERO ideas on how to proceed.

I'm desperately trying to post a post with an image and an image URL via the Facebook Graph API. No matter what I do, I always get error messages.

Does anyone here have any sample code or ideas on how to implement this with Python? I would be very grateful for constructive answers!

import requests from io import BytesIO def post_facebook_photo(message, image_url):     access_token = 'DEIN_ACCESS_TOKEN'     feed_url = "https://graph.facebook.com/v20.0/me/feed"          try:                image_response = requests.get(image_url)         image_response.raise_for_status()     except requests.exceptions.RequestException as e:         print(f"Fehler beim Herunterladen des Bildes: {e}")         return     image_file = BytesIO(image_response.content)             photo_upload_url = "https://graph.facebook.com/v20.0/me/photos"     photo_data = {'access_token': access_token}     photo_files = {'file': ('image.jpg', image_file, 'image/jpeg')}          photo_response = requests.post(photo_upload_url, data=photo_data, files=photo_files)     photo_response_data = photo_response.json()     if 'id' in photo_response_data:         photo_id = photo_response_data['id']         post_data = {             'message': message,             'attached_media': [{'media_fbid': photo_id}],             'access_token': access_token         }                  post_response = requests.post(feed_url, json=post_data)         return post_response.json()     else:         return photo_response_data response = post_facebook_photo("Hier ist ein neues Bild!", "IMAGE-URL") print(response) 

I hope your day is going well. When I make a request using this endpoint:

  url = "https://graph.instagram.com/access_token"   params = {       "grant_type": "ig_exchange_token",       "client_secret": client_secret,       "access_token": short_lived_access_token   } 

I encounter the following error:

{'error': {'message': 'Unsupported request - method type: post', 'type': 'IGApiException', 'code': 100, 'fbtrace_id': 'Ape_-PbPFO_idh_eqtMB3jz'}} 

I'm unsure of the problem. I have added a verified business, but I have not submitted my app for app review. Should I do that first?

Additionally, it's not just this endpoint; I encounter issues with every endpoint I attempt to request, although I can obtain the short-lived access token without any issues.

I tried to exchange short lived token for the long lived once, and I was expecting to recieve the long lived token

Using the graph API pages search to pull in locations, e.g.

pages/search?q=Scranton&fields=id,name,location,link

I used to be able to pull in results such as:

  • Rockville Centre, New York (108007899221124)
  • Lakeland Florida (334882786648235)

Now, only specific page-backed addresses are pulled in. I see this behavior in other meta connected apps I've tried, is there a change I am unaware of?

A search for Lakeland Florida used to pull in that location / ID as recently as a couple of weeks ago. Many other generic place names are missing.

I have created an app on the Facebook developer account and I'm using those details to implement Facebook login in my react-native app. Are there any settings available on the Facebook Developer Account where I can allow login specifically only for my react-native app E.g. by specifying my package name so that the login works only for the app with that package name.