|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Facebook に定期的に投稿する場合、生産性を向上させる最良の方法の 1 つは、自動投稿スケジューラを使用することです。そのための 1 つの方法は、カレンダーまたは cron ジョブに添付できる単純な Python スクリプトを作成することです。では、そのスクリプトの作成を見てみましょう。
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 に定期的に投稿する場合に生産性を向上させる 1 つの方法は、自動投稿スケジューラを使用することです。そのための 1 つの方法は、カレンダーまたは cron ジョブに添付できる単純な Python スクリプトを作成することです。では、そのスクリプトの作成を見てみましょう。
## 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 スクリプトを開始する前に Facebook アプリを作成する必要があります。幸いなことに、それは難しくありません。
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. [App Domains] で、Python スクリプトをホストする Web サイトまたはサーバーのドメイン名を入力します。たとえば、スクリプトが URL「https://example.com/script.py」の個人 Web サイトでホストされる場合は、ここに「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. 最後に、アプリのアクセス トークンを生成する必要があります。左側のサイドバーで「App Tokens」をクリックします。
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
'アクセストークン': アクセストークン
}
}
# Make the POST request to Facebook
# Facebook に POST リクエストを送信する
response = requests.post(post_url, data=payload)
応答 = request.post(post_url, データ = ペイロード)
# Check if the post was successful
# 投稿が成功したかどうかを確認する
if response.status_code == 200:
response.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) までご連絡ください。速やかに削除させていただきます。
-
- 今日のミルクロードはジェミニがお届けします
- 2024-10-12 06:25:01
- ミームと市場の最新情報を一度に 1 つずつ紹介しながら、暗号通貨の世界を案内するニュースレターです。