How's authentication, can I use in pythonI use n8n
Is this achievable with python? I am currently testing rest api but have issues with 401Easiest way to do this is to connect to mysql from the bot, and do an insert. This way, you have full control of what the bot does, and there is no other auth/plugin involved other than the mysql connection itself.
Ofcourse this is possible with python.Is this achievable with python? I am currently testing rest api but have issues with 401
https://pynative.com/python-mysql-insert-data-into-database-table/
You then have to include header information like the status, and the article.var client = new RestClient($"{website}/wp-json/wp/v2/posts?categories={category}");
import requestsIts easy, you just post to a wordpress URL of your site. If you want to get started, figure out how to do it in the postman app first, that's what I figured out. Once you have it in postman, you can export the code to whatever compatible language. I built a wordpress poster in c#. Posts an article, and you get a response back when you post, so you can validate.
Here is what I have in C# to post:
You then have to include header information like the status, and the article.
If you are using python it will still be easy enough, but trust me when I say get it working in postman if you can first, as that opens up a whole new world of easier development with API's
import requests
# Set the Wordpress site URL and API endpoint
wp_url = "your url"
wp_api_endpoint = "/wp-json/wp/v2/posts"
# Set the authentication credentials for the Wordpress API
wp_username = "username"
wp_password = "password"
# Set the content for the blog post
blog_content = {
"title": title,
"content": blogpost
"status": "publish",
"categories": [1]
}
# Use the Wordpress REST API to create a new blog post
response = requests.post(wp_url + wp_api_endpoint, json=blog_content, auth=(wp_username, wp_password))
# Check the response status code to see if the blog post was created successfully
if response.status_code == 201:
print("Blog post created successfully!")
else:
print("Error creating blog post")
print(response.text)
Thanks buddy! Finally got it posting, it wanted me to define title and post so I just added variables for them both, which I can use as containers for new content now. We are getting there for automated blogging really appreciate the helpMake sure you download the Jetpack plugin on Wordpress and activate it.
To create a new post on a WordPress site using the WordPress REST API and the command line, you will need to do the following:
Here is an example of how you might create a new post using curl:
- Obtain an API key for the WordPress site. This can typically be done by logging in to the WordPress site as an administrator and going to the "Users" section.
- Install the curl command line tool, if it is not already installed on your system.
- Use the curl command to send a POST request to the WordPress REST API endpoint for creating posts, specifying the necessary parameters in the request body. The endpoint for creating posts is typically https://example.com/wp-json/wp/v2/posts.
Copy code
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json"-d '{"title":"My New Post","content":"This is the content of my new post."}' https://example.com/wp-json/wp/v2/posts
This example assumes that you have replaced YOUR_API_KEY with the actual API key for your WordPress site, and example.com with the domain of your WordPress site.
You can also use the curl command to specify additional parameters in the request, such as the post status, author, and categories. For a full list of available parameters, you can refer to the WordPress REST API documentation.
How are you getting and using keywordsI am using xmlrpc library to post 100 to 1k articles per day on my blog automatically using python.
I’m not totally agreed. With direct mysql injection you can have encoding issue that will affect the entire blog.Easiest way to do this is to connect to mysql from the bot, and do an insert. This way, you have full control of what the bot does, and there is no other auth/plugin involved other than the mysql connection itself.
Go to “admin user” profile in the dashboard of WP, at the bottom of the page you will find a button to generate an api key to authenticate in wp rest api.Anyone found the easiest way to auto post to WordPress from the cli?
Rest api seems interesting but not sure how to authenticate
It’s not “mysql injection” but mysql insert. It is the same thing as adding through api/admin. Only in this case your python script adds the post instead of the wp’s php function which does the same. I know this works because I have done many of such bots before. None had any problem. If you are having encoding problems, look into your source of content first.I’m not totally agreed. With direct mysql injection you can have encoding issue that will affect the entire blog.
Good to know. I’ll testIt’s not “mysql injection” but mysql insert. It is the same thing as adding through api/admin. Only in this case your python script adds the post instead of the wp’s php function which does the same. I know this works because I have done many of such bots before. None had any problem. If you are having encoding problems, look into your source of content first.
有人找到了从 cli 自动发布到 WordPress 的最简单方法吗?
Rest api 似乎很有趣,但不确定如何进行身份验证