|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
如果您經常在 Facebook 上發帖,提高工作效率的最佳方法之一就是使用自動發文調度程式。一種方法是建立一個簡單的 Python 腳本,您可以將其附加到日曆或 cron 作業。現在讓我們看看創建該腳本。
One way to improve productivity if you regularly post to Facebook is with an automatic post scheduler. One way to do that is to create a simple Python script that you can attach to a calendar or cron job. Let’s look at creating that script now.
如果您經常在 Facebook 上發帖,那麼提高工作效率的一種方法是使用自動發文調度程式。一種方法是建立一個簡單的 Python 腳本,您可以將其附加到日曆或 cron 作業。現在讓我們看看創建該腳本。
## Creating a Facebook app
## 建立 Facebook 應用程式
Any Python script that we create to post on Facebook will use a Facebook app to do so, and you will need to make it before we can start with the Python script. Luckily, it’s not hard.
我們創建的要在 Facebook 上發布的任何 Python 腳本都將使用 Facebook 應用程式來執行此操作,您需要先完成它,然後才能開始使用 Python 腳本。幸運的是,這並不難。
1. Go to the Meta Developers site and log in.
1. 前往 Meta Developers 站點並登入。
2. Click on “My Apps” in the top navigation bar.
2. 點選頂部導覽列中的「我的應用程式」。
3. Click on “Create New App.”
3. 按一下「建立新應用程式」。
4. Select “Manage Page” as the app type and click on “Continue.”
4. 選擇「管理頁面」作為應用程式類型,然後按一下「繼續」。
5. Enter a display name for your app and click on “Create App.”
5. 輸入應用程式的顯示名稱,然後按一下「建立應用程式」。
6. Click on “Skip Quick Start” and then on “Settings.”
6. 按一下“跳過快速啟動”,然後按一下“設定”。
7. In the left sidebar, click on “Basic Settings.”
7. 在左側邊欄中,按一下「基本設定」。
8. Under “App Domains,” enter the domain name of the website or server that will be hosting your Python script. For example, if your script will be hosted on your personal website at the URL “https://example.com/script.py,” then you would enter “example.com” here.
8. 在「應用程式網域」下,輸入將託管 Python 腳本的網站或伺服器的網域名稱。例如,如果您的腳本將託管在您的個人網站上,URL 為“https://example.com/script.py”,那麼您應該在此輸入“example.com”。
9. Click on “Save Changes.”
9. 點選「儲存變更」。
10. Next, we need to add our Facebook page to the app. In the left sidebar, click on “Pages.”
10. 接下來,我們需要將 Facebook 頁面加入應用程式。在左側邊欄中,按一下「頁面」。
11. Click on the “Add Page” button and select the page that you want to give your app permission to post on.
11. 按一下「新增頁面」按鈕,然後選擇您想要授予應用程式發佈權限的頁面。
12. Click on the “Assign” button and then on the “Done” button.
12. 按一下「指派」按鈕,然後按一下「完成」按鈕。
13. Finally, we need to generate an access token for our app. In the left sidebar, click on “App Tokens.”
13. 最後,我們需要為我們的應用程式產生存取權杖。在左側邊欄中,按一下「應用程式令牌」。
14. Click on the “Generate New Token” button and select “User Access Token” from the dropdown menu.
14. 按一下「產生新令牌」按鈕,然後從下拉式選單中選擇「使用者存取權杖」。
15. Click on the “Generate” button and copy the access token that is displayed. You will need this token later when we configure our Python script.
15. 按一下「產生」按鈕並複製顯示的存取權杖。稍後當我們配置 Python 腳本時,您將需要此令牌。
## Get your page ID
## 取得你的頁面ID
With the app created, we can use it as a go-between between Python and Facebook, but to make a post, we will need our page ID.
創建應用程式後,我們可以將其用作 Python 和 Facebook 之間的中間人,但要發布帖子,我們需要頁面 ID。
1. Go to the Facebook page that you want to post on.
1. 前往您要發佈的 Facebook 專頁。
2. In the URL address bar, look for the string of numbers that appears after “facebook.com/.” This is your page ID. For example, if the URL of your page is “https://www.facebook.com/geeksides/,” then your page ID is “geeksides.”
2. 在 URL 網址列中,找出「facebook.com/」後面出現的數字字串。這是您的頁面 ID。例如,如果您的頁面 URL 是“https://www.facebook.com/geeksides/”,那麼您的頁面 ID 就是“geeksides”。
## Get your page access token
## 取得您的頁面存取權令牌
The final thing we need before we can write our Python script is our page access token.
在編寫 Python 腳本之前,我們需要的最後一件事是頁面存取權杖。
1. Go to the Graph API Explorer site and log in.
1. 前往 Graph API Explorer 網站並登入。
2. In the left sidebar, click on “User Access Token.”
2. 在左側邊欄中,按一下「使用者存取權杖」。
3. Select the page that you want to get the access token for from the dropdown menu.
3. 從下拉式選單中選擇您想要取得存取權杖的頁面。
4. Click on the “Generate Access Token” button and copy the access token that is displayed. You will need this token later when we configure our Python script.
4. 按一下「產生存取權杖」按鈕並複製顯示的存取權杖。稍後當我們配置 Python 腳本時,您將需要此令牌。
## The Python Script
## Python 腳本
If you don’t know how to run this script and are just getting started with Python, check out our long list of tutorials.
如果您不知道如何執行此腳本並且剛開始使用 Python,請查看我們的一長串教學。
You can copy and paste the following Python script into a text file and run it to make a post on the Facebook page you have the access code for:
您可以將以下 Python 腳本複製並貼上到文字檔案中,然後運行它以在您擁有存取程式碼的 Facebook 頁面上發佈:
```python
````蟒蛇
# First, install the Requests if you don't already have it
# 首先,如果您還沒有安裝 Requests,請安裝它
pip install requests
pip 安裝請求
# Here is the complete code:
# 這是完整的程式碼:
import requests
導入請求
# Replace these with your actual access token and page ID or user ID
# 將這些替換為您的實際存取權杖和頁面 ID 或使用者 ID
access_token = 'your_facebook_access_token'
access_token = 'your_facebook_access_token'
page_id = 'your_page_or_user_id'
page_id = 'your_page_or_user_id'
message = 'Hello, this is a test post from my Python script!'
message = '您好,這是我的 Python 腳本的測試帖子! '
# Define the URL for posting to the Facebook Graph API
# 定義發佈到 Facebook Graph API 的 URL
post_url = f'https://graph.facebook.com/v17.0/{page_id}/feed'
post_url = f'https://graph.facebook.com/v17.0/{page_id}/feed'
# Parameters to be sent with the request
# 與請求一起傳送的參數
payload = {
有效負載={
'message': message,
'消息':消息,
'access_token': access_token
'access_token':access_token
}
}
# Make the POST request to Facebook
# 向 Facebook 發出 POST 請求
response = requests.post(post_url, data=payload)
回應 = requests.post(post_url, data=payload)
# Check if the post was successful
# 檢查貼文是否成功
if response.status_code == 200:
如果回應.status_code == 200:
print('Post published successfully!')
print('帖子發布成功!')
else:
別的:
print(f'Failed to post. Status code: {response.status_code}')
print(f'發布失敗。狀態碼:{response.status_code}')
print(f'Error: {response.text}')
print(f'錯誤:{response.text}')
```
````
To run this script, first change the code to include your page ID and access code where it says to do so. Then, save the file with a .py extension (e.g.,
若要執行此腳本,請先變更程式碼以包含您的頁面 ID 和存取程式碼(在其指定的位置)。然後,使用 .py 副檔名儲存檔案(例如,
免責聲明:info@kdj.com
所提供的資訊並非交易建議。 kDJ.com對任何基於本文提供的資訊進行的投資不承擔任何責任。加密貨幣波動性較大,建議您充分研究後謹慎投資!
如果您認為本網站使用的內容侵犯了您的版權,請立即聯絡我們(info@kdj.com),我們將及時刪除。
-
- USDC 原生於 Sui 鏈
- 2024-10-12 06:20:01
- Circle 在 Sui 區塊鏈上引入了原生 USDC,讓開發者和用戶無需依賴橋樑即可直接存取 USDC。
-
- 唯鏈機會:5年來最低價格-累積階段
- 2024-10-12 06:20:01
- Vechain、VETBTC 正在發生一些令人驚訝的事情。目前該貨幣對的交易價格處於過去五年來的最低點。