Failed to add focus keyword / Auto blog posting focus keyword input code error

#828838
  • Resolved Ashley Lee
    Rank Math free

    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?

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting support.

    To update the data of our plugin using the REST API you need to first register the metadata fields that you want to update and then use the WordPress REST API to update those custom fields using something similar to this: https://torquemag.io/2015/07/working-with-post-meta-data-using-the-wordpress-rest-api/

    As an example, the custom field for the focus keyword in our plugin is called rank_math_focus_keyword.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Failed to add focus keyword / Auto blog posting focus keyword input code error’ is closed to new replies.