-
import requests
from requests.auth import HTTPBasicAuth
import time# 설정
wordpress_url = “https://my.homepage.com/wp-json/wp/v2/posts”
meta_key = ‘rank_math_focus_keyword’ # 정확한 메타 키를 확인하세요
meta_value = ‘diet lunchbox’
title = ‘new post title’
content = ‘Enter post content here.’# 포스트 생성
response = requests.post(
wordpress_url,
json={
‘title’: title,
‘content’: content,
‘status’: ‘draft’ # 또는 ‘draft’ #publish
},
auth=HTTPBasicAuth(‘Diet_Diva’, ‘dsIl 8vIF gW0T 0N6o Zac6 fUEB’),
headers={‘Content-Type’: ‘application/json’}
)if response.status_code == 201:
post_id = response.json().get(‘id’)
print(“Post created successfully: “, response.json().get(‘link’))# 약간의 지연을 추가하여 포스트가 완전히 저장되도록 함
time.sleep(2) # 2초 지연# 포스트 생성 후 메타 데이터 업데이트
meta_update_url = f”{wordpress_url}/{post_id}”
meta_response = requests.post(
meta_update_url,
json={
‘meta’: {
meta_key: meta_value
}
},
auth=HTTPBasicAuth(‘my id’, ‘my pw’),
headers={‘Content-Type’: ‘application/json’}
)if meta_response.status_code == 200:
print(“Meta updated successfully.”)
updated_meta = meta_response.json().get(‘meta’, {})
print(“Updated Meta:”, updated_meta)
if meta_key in updated_meta and updated_meta[meta_key] == meta_value:
print(f”Focus keyword ‘{meta_value}’ successfully added.”)
else:
print(f”Failed to add focus keyword ‘{meta_value}’.”)
else:
print(f”Failed to update meta: {meta_response.status_code} {meta_response.text}”)
else:
print(f”Failed to create post: {response.status_code} {response.text}”)error//
C:\blog_test_000\myenv\Scripts\python.exe “C:\autoblog_money_shop\test_focus keyword.py”
Post created successfully: https://my.homepage.com/?p=794
Meta updated successfully.
Updated Meta: {‘footnotes’: ”}
Failed to add focus keyword ‘diet lunchbox’.Process finished with exit code 0
While posting automatic blog posts, the code entering the focus keyword fails.
Is there a solution?
Each individual posting should be entered as a focus keyword.
I checked the meta key, and it was correct.
I look forward to hearing from you.meta_key = ‘rank_math_focus_keyword’ –> Is this correct?
The ticket ‘Failed to add focus keyword / Auto blog posting focus keyword input code error’ is closed to new replies.