OnePost

FREEMIUM
By Adam Darrah | Updated hace un mes | Social
Popularity

8.5 / 10

Latency

954ms

Service Level

100%

Health Check

N/A

Back to All Tutorials (10)

Post with Twitter

Before starting this tutorial, make sure you have signed in with Twitter so that you have at least one AuthorizedPage record.

Get the Authorized Page ID

First, we’ll use the Get All Authorized Pages API endpoint to find our Twitter AuthorizedPage ID. We’ll need this in order to make a post.

curl --request GET \
> --url 'https://onepost1.p.rapidapi.com/api/v1/authorized_pages?secret_key=sk-cbe...' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...'

{"current_page":1,"per_page":30,"total_entries":3,"collection":[{"id":7,"authorization_id":6,"name":"1bertlol","service_id":"81534513","type":"AuthorizedPages::Twitter","info":{"id":81534513},"created_at":"2021-02-19T17:44:46.869-05:00","updated_at":"2021-02-19T17:44:46.869-05:00"}]}

From this API request, we can see that we have an AuthorizedPage with ID 7. Now, we can use this to construct our post using the Create a Post API endpoint.

curl --request POST \
> --url 'https://onepost1.p.rapidapi.com/api/v1/posts?secret_key=sk-cbe...' \
> --header 'content-type: application/json' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...' \
> --data '{
>     "post": {
>         "authorized_page_ids": [
>             7
>         ],
>         "body": "Batman ninja approves",
>         "image_url": "https://blacknerdproblems.com/wp-content/uploads/2018/04/1batmanninja1.jpg"
>     }
> }'

{"id":8,"body":"Batman ninja approves","created_at":"2021-02-22T10:18:42.324-05:00","updated_at":"2021-02-22T10:18:42.342-05:00","state":"draft","publish_at":null,"authorized_page_ids":[7],"image_url":"https://onepost-aws-assets.s3.amazonaws.com/mptbdvq1fofl74px1oadkhzhcz8j?response-content-disposition=inline%3B%20filename%3D%221batmanninja1.jpg%22%3B%20filename%2A%3DUTF-8%27%271batmanninja1.jpg\u0026response-content-type=image%2Fjpeg\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIAZN2CXLF3YEIHHHFZ%2F20210222%2Fus-east-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210222T151842Z\u0026X-Amz-Expires=300\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=005cb6b30eca08a6dcd0182128bc0526e801f68295266e6995f23bf0ceb165c9","social_posts":[{"id":8,"post_id":8,"created_at":"2021-02-22T10:18:42.329-05:00","updated_at":"2021-02-22T10:18:42.329-05:00","type":"SocialPosts::Twitter","state":"unsent","authorized_page_id":7}]}

We’ve just created a new “draft” Post with an ID of 8. While a post is in the “draft” state, it can be updated using the Update a Post API endpoint if needed.

Additionally, notice that an “unsent” SocialPost record was created (with an ID of 8) for our Twitter AuthorizedPage. SocialPost records represent a single post to an AuthorizedPage. This is the record where the performance of an individual post is tracked over time (such as the number of retweets or hearts). These records are created or destroyed by updating the authorized_page_ids of the Post record.

Also notice that content is not published to the AuthorizedPage while the post is in the draft state. There are two ways to publish a post:

  1. You can set the publish_at field on the Post when it is created or by updating it. This field can be used to have the post publish automatically at a certain time.
  2. You can publish the post by using the Publish a Post API endpoint.

For this tutorial, we will publish our POST using the API.

curl --request POST \
> --url 'https://onepost1.p.rapidapi.com/api/v1/posts/8/publish?secret_key=sk-cbe...' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...'

{"id":8,"body":"Batman ninja approves","created_at":"2021-02-22T10:18:42.324-05:00","updated_at":"2021-02-22T10:27:31.552-05:00","state":"publishing","publish_at":null,"authorized_page_ids":[7],"image_url":"https://onepost-aws-assets.s3.amazonaws.com/mptbdvq1fofl74px1oadkhzhcz8j?response-content-disposition=inline%3B%20filename%3D%221batmanninja1.jpg%22%3B%20filename%2A%3DUTF-8%27%271batmanninja1.jpg\u0026response-content-type=image%2Fjpeg\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIAZN2CXLF3YEIHHHFZ%2F20210222%2Fus-east-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210222T152731Z\u0026X-Amz-Expires=300\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=7e8debdb590b45e119d0d7993cc9275bcd7c1ed1922598856983b3f6a2c6f728","social_posts":[{"id":8,"post_id":8,"created_at":"2021-02-22T10:18:42.329-05:00","updated_at":"2021-02-22T10:18:42.329-05:00","type":"SocialPosts::Twitter","state":"unsent","authorized_page_id":7}]}

When you check Twitter, you’ll see that the post has been published!

Finally, if you use the Get a Social Post API Endpoint to check the SocialPost, you’ll see that we’ve begun to track the data for the post:

curl --request GET \
> --url 'https://onepost1.p.rapidapi.com/api/v1/social_posts/8?secret_key=sk-cbe...' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...'

{"id":8,"post_id":8,"created_at":"2021-02-22T10:37:47.070-05:00","updated_at":"2021-02-22T10:38:36.686-05:00","type":"SocialPosts::Twitter","state":"sent","authorized_page_id":7,"service_data":{"id":1363875852656779268,"retweet_count":0,"favorite_count":0},"service_data_updated_at":"2021-02-22T10:40:06.410-05:00"}