OnePost

FREEMIUM
By Adam Darrah | Updated a month ago | Social
Popularity

8.5 / 10

Latency

954ms

Service Level

100%

Health Check

N/A

Back to All Tutorials (10)

Post with Facebook & Instagram

Before starting this tutorial, make sure you have signed in with Facebook 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 Facebook & Instagram AuthorizedPage IDs. 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":2,"collection":[{"id":11,"authorization_id":9,"name":"Opendate","service_id":"115546706803453","type":"AuthorizedPages::Facebook","info":{"id":"115546706803453","link":"https://www.facebook.com/115546706803453","name":"Opendate","about":"The operating system for music venues.  Discover and book talent the modern way.  Organize and execute shows and keep everyone on the same page.","cover":{"id":"115550003469790","source":"https://scontent.xx.fbcdn.net/v/t1.0-9/s720x720/95215860_115550006803123_6905534502538313728_o.png?_nc_cat=100\u0026ccb=3\u0026_nc_sid=dd9801\u0026_nc_ohc=JtjgqYfCQ1wAX_Lc1QU\u0026_nc_ht=scontent.xx\u0026_nc_tp=30\u0026oh=56f00d7d5d1edf80f0ef68402f0879fa\u0026oe=60585868","cover_id":"115550003469790","offset_x":50,"offset_y":38},"access_token":"EAA...","instagram_business_account":{"id":"17841421827949046"}},"created_at":"2021-02-22T10:51:50.705-05:00","updated_at":"2021-02-22T10:51:50.705-05:00"},{"id":12,"authorization_id":9,"name":"opendate","service_id":"17841421827949046","type":"AuthorizedPages::Instagram","info":{"id":"17841421827949046","name":"Opendate","ig_id":21672375598,"website":"http://opendate.io/","username":"opendate","biography":"Transform how you discover, analyze, \u0026 book the best talent for your venue with our industry-leading software and events platform for venues \u0026 agents","follows_count":114,"followers_count":22,"profile_picture_url":"https://scontent.xx.fbcdn.net/v/t51.2885-15/98106443_862105484292154_3771255549614620672_n.jpg?_nc_cat=100\u0026ccb=3\u0026_nc_sid=86c713\u0026_nc_ohc=J8Jr3LmW1toAX9rApzu\u0026_nc_ht=scontent.xx\u0026oh=415e78426229157f11ebe2b388db457e\u0026oe=6057FFCC"},"created_at":"2021-02-22T10:51:50.904-05:00","updated_at":"2021-02-22T10:51:50.904-05:00"}]}

We have two AuthorizedPage records. We have one for a Facebook page (with an ID of 11) and one for an Instagram page (with an ID of 12). We can create a post for either the Facebook page OR the Instagram page, but for this tutorial, we’ll make a single post to both pages. Let’s use the Create a Post API endpoint to create a new draft post.

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": [
>             11,
>             12
>         ],
>         "body": "Red Rocks!",
>         "image_url": "https://www.colorado.com/sites/default/files/styles/1000x685/public/redrocksfavorite_VD.jpg?itok=_6q91zkg"
>     }
> }'

{"id":10,"body":"Red Rocks!","created_at":"2021-02-22T11:03:07.785-05:00","updated_at":"2021-02-22T11:03:07.821-05:00","state":"draft","publish_at":null,"authorized_page_ids":[11,12],"image_url":"https://onepost-aws-assets.s3.amazonaws.com/rzoe1w86rvi6yoydt52x335q68sp?response-content-disposition=inline%3B%20filename%3D%22redrocksfavorite_VD.jpg%22%3B%20filename%2A%3DUTF-8%27%27redrocksfavorite_VD.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=20210222T160307Z\u0026X-Amz-Expires=300\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=fb516d7660a97eb9438b6e5e91fca7155a5425e415fcc873b62bb6ef3784064c","social_posts":[{"id":10,"post_id":10,"created_at":"2021-02-22T11:03:07.794-05:00","updated_at":"2021-02-22T11:03:07.794-05:00","type":"SocialPosts::Facebook","state":"unsent","authorized_page_id":11},{"id":11,"post_id":10,"created_at":"2021-02-22T11:03:07.802-05:00","updated_at":"2021-02-22T11:03:07.802-05:00","type":"SocialPosts::Instagram","state":"unsent","authorized_page_id":12}]}

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

Additionally, notice that we have two “unsent” SocialPost records (with IDs of 10 and 11). 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 likes for Facebook). 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/10/publish?secret_key=sk-cbe...' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...'

{"id":10,"body":"Red Rocks!","created_at":"2021-02-22T11:03:07.785-05:00","updated_at":"2021-02-22T11:06:54.605-05:00","state":"publishing","publish_at":null,"authorized_page_ids":[11,12],"image_url":"https://onepost-aws-assets.s3.amazonaws.com/rzoe1w86rvi6yoydt52x335q68sp?response-content-disposition=inline%3B%20filename%3D%22redrocksfavorite_VD.jpg%22%3B%20filename%2A%3DUTF-8%27%27redrocksfavorite_VD.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=20210222T160654Z\u0026X-Amz-Expires=300\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=55f4dd1bc7bc3380eeac5745a45f93829420c937c0c10040f4cad75de7e0bc53","social_posts":[{"id":10,"post_id":10,"created_at":"2021-02-22T11:03:07.794-05:00","updated_at":"2021-02-22T11:03:07.794-05:00","type":"SocialPosts::Facebook","state":"unsent","authorized_page_id":11},{"id":11,"post_id":10,"created_at":"2021-02-22T11:03:07.802-05:00","updated_at":"2021-02-22T11:03:07.802-05:00","type":"SocialPosts::Instagram","state":"unsent","authorized_page_id":12}]}

Then, give it a moment and you’ll see your posts appear!

Once the post has been published, you can use the Get a Social Post API endpoint to see the stats for a single SocialPost.

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

{"id":11,"post_id":10,"created_at":"2021-02-22T11:03:07.802-05:00","updated_at":"2021-02-22T11:06:54.765-05:00","type":"SocialPosts::Instagram","state":"sent","authorized_page_id":12,"service_data":{"id":"18198871927012413","ig_id":"2514820752012819075","owner":{"id":"17841421827949046"},"caption":"Red Rocks!","username":"opendate","media_url":"https://scontent.cdninstagram.com/v/t51.2885-15/152228955_3718910591497584_7707048042026266653_n.jpg?_nc_cat=106\u0026ccb=3\u0026_nc_sid=8ae9d6\u0026_nc_ohc=GSu5juh9iwgAX83h3Vc\u0026_nc_ht=scontent.cdninstagram.com\u0026oh=cdc721234892db44183dd3bf40686e28\u0026oe=6057E1F0","permalink":"https://www.instagram.com/p/CLmcCZdgTqD/","shortcode":"CLmcCZdgTqD","timestamp":"2021-02-22T16:06:59+0000","like_count":0,"media_type":"IMAGE","comments_count":0,"is_comment_enabled":true},"service_data_updated_at":"2021-02-22T11:10:09.628-05:00"}