Facebook Upload a Video Graph Api Permission

In this commodity we will discuss how to simplify your facebook folio appointment by automating the facebook page posts with python and facebook graph API.

We will cover the following topics in this commodity:

  • Intro to Facebook Graph API
  • Getting your facebook page access token
  • Sending a mail to your facebook page using Graph API and python
  • Sending a photo to your facebook page using Graph API and python
  • How to swap brusk life admission token for a long life access token
  • Send posts to Facebook on a schedule

Intro to Facebook Graph API

Y'all tin can access the Facebook Graph API on this link: https://developers.facebook.com/docs/graph-api/ — the documentation covers code snippets for interacting with the API from getting your access tokens to sending posts to facebook.

The Facebook Graph API provides url endpoints that yous can transport GET and POST requests to, in order to interact with your facebook page or ship data, posts to your facebook account. You can utilise the API to: (1) Read the messages on your timeline, (two) send messages, (3) read posts, (4) create posts, edit posts or even delete posts. The API is a powerful tool to interact with your facebook account or page programatically, hence providing a tool to automate your facebook.

We are going to focus on how to use the API to automate posts, specifically on a Facebook page.

Before you tin access the graph API, you need access tokens. These are like digital keys that unlock your account and enable you to collaborate with it programatically.

Getting your Facebook Folio Access Tokens

We are going to start past getting the short-life access tokens, these are the tokens you can get from the facebook developer front-end. Go to the url: https://developers.facebook.com/

Create a facebook developer account and log in to the dashboard. At the elevation left, click on the "create app" green button:

In the next page, select an app name and printing enter.

And then go to the tools, and press the beginning button on the dropdown — Graph API Explorer.

In this page, you volition be able to select your access tokens. Follow the steps below to get your Facebook page Graph API admission token:

Steps to get your facebook graph API page access token

Send a post to Facebook page using Facebook Graph API Access Token with Python

You lot volition also need a page ID — for the facebook page you would like to mail to.You can get your page ID directly from your facebook page, under "about" tab. Copy this ID and paste it in your code.

We will be using the requests library, install information technology beneath:

          pip install requests        

This is the code for creating a postal service:

          import requests          #Your Admission Keys
page_id_1 = 123456789
facebook_access_token_1 = 'paste-your-folio-access-token-hither'
msg = 'Purple Ombre Bob Lace Wig Natural Human Pilus now available on https://lace-wigs.co.za/'
post_url = 'https://graph.facebook.com/{}/feed'.format(page_id_1)
payload = {
'bulletin': msg,
'access_token': facebook_access_token_1
}
r = requests.post(post_url, data=payload)
impress(r.text)

If you become an error at this stage, there could be either: (1) something wring with you folio ID or (ii) something wrong with your access token. Review the steps to a higher place for accessing your tokes making sure: you accept selected a Page access token, with the right permissions. The permissions you need are:

  • pages_show_list
  • pages_read_engagement
  • pages_manage_posts
  • public_profile

Send an epitome to Facebook Page using Python

To ship an image to your facebook folio, you tin use the code below:

          import requests          page_id_1 = 123456789
facebook_access_token_1 = 'paste-your-page-access-token-here'
image_url = 'https://graph.facebook.com/{}/photos'.format(page_id_1)
image_location = 'http://image.careers-portal.co.za/f_output.jpg'
img_payload = {
'url': image_location,
'access_token': facebook_access_token_1
}
#Transport the Postal service request
r = requests.postal service(image_url, information=img_payload)
print(r.text)

The image we are sending is located on the internet at the location: http://prototype.careers-portal.co.za/f_output.jpg

How to swop a brusque lived token for a long loved token

The process we discussed higher up for obtaining an access token from the Graph API dashboard — only provides curt-lived tokens, that are good for an hour from consequence. This means you tin can write any meaningful code with it, equally the code expires in an hour.

Get back to the Graph API dashboard and obtain a short lived USER admission token. This is different from the token we used to post on the folio. On the dropdown — select USER token, instead of PAGE token.

Once you go this token, you can swop it for a long-lived USER access token by sending a Curlicue request like this:

          coil -i -X Get "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={brusk-lived-user-access-token}"

This long-lived USER access token volition at present be valid for 60days, as opposed to 1hour for the brusk-lived token.

Only nosotros demand a page access token, and then utilise the post-obit CURL asking to swop your USER access token for a Page access token:

          ringlet -i -X Become "https://graph.facebook.com/{page-id}?
fields=access_token&
access_token={user-access-token}"

It is all-time to use a long-lived USER token in this request, equally it returns a page token that does not have an expiration date — according to Facebook, not yet tested.

You lot volition so become a page admission token, you tin can at present utilise in your code.

Send posts to Facebook Page with Facebook Graph API on a schedule with Python

At this stage we will use the Python schedule library to schedule the posts on a daily basis. You tin can create a list of posts to schedule consecutively or randomly.

Start past installing schedule

          pip install schedule        

The code will look similar:

          import requests
import schedule
def sendPost1():
sending the post . . . . .
def sendPost2():
sending the mail . . . . .
schedule.every().day.at("08:30").do(sendPost1)
schedule.every().day.at("09:15").do(sendPost2)
while True:
schedule.run_pending()
fourth dimension.slumber(1)

johnsconces1975.blogspot.com

Source: https://medium.com/nerd-for-tech/automate-facebook-posts-with-python-and-facebook-graph-api-858a03d2b142

0 Response to "Facebook Upload a Video Graph Api Permission"

Enregistrer un commentaire

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel