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)

Sign in with Facebook

Before starting this tutorial, make sure you have added a Facebook (& Instagram) Provider to your OnePost API.

Get the Required Provider ID

First, we’ll use the Get All Providers API endpoint to find our Facebook Provider ID. We’ll need this in order to get our link to sign in.

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

{"current_page":1,"per_page":30,"total_entries":1,"collection":[{"id":8,"type":"Providers::Facebook","api_key":"420...","created_at":"2021-02-19T17:20:10.330-05:00","updated_at":"2021-02-19T17:20:10.330-05:00","callback_url":null,"api_secret_key":"908..."}]}

Let’s note that our Facebook Provider has an ID of 8 in OnePost.

Create the Authorization

Now that we have the Provider ID, we’ll use the Create an Authorization API endpoint to assist in creating our Authorization. An Authorization in OnePost is a model representing a user’s permission for your application to use their account. This record is created when they sign into the Provider (such as Twitter or Facebook) to grant access through their web browser. Let’s use the API to get the URL we’ll need:

curl --request POST \
> --url 'https://onepost1.p.rapidapi.com/api/v1/authorizations?secret_key=sk-7a0...' \
> --header 'content-type: application/json' \
> --header 'x-rapidapi-host: onepost1.p.rapidapi.com' \
> --header 'x-rapidapi-key: 9d0...' \
> --data '{
>     "authorization": {
>         "provider_id": 8
>     }
> }'

{"instructions":["Perform the following steps to complete the authorization process:","  1. In your web browser, navigate to the provided URL.","  2. Sign in to Facebook.","  3. You will be redirected back to the original application."],"url":"https://api.getonepost.com/users/auth/facebook?provider_id=8&public_key=pk-7a0..."}

You can see that when we call this endpoint, we get back a unique URL (in a Production environment you would simply have a link from your website with this URL that the user can click on). Let’s copy and paste this into our web browser to try it out.

Notice that once you sign in you are redirected back to OnePost. You are able to specify where the user should be redirected with the callback_url field on the Provider record. (Note: Look for the X-OnePost-Authorization-Id, X-OnePost-Provider-Id, and X-OnePost-Public-Key header values in the request sent to your callback_url)

Once the user has signed into Facebook, you can call the Get All Authorizations endpoint to see the new Authorization record.

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

{"current_page":1,"per_page":30,"total_entries":2,"collection":[{"id":7,"created_at":"2021-02-19T18:03:56.419-05:00","updated_at":"2021-02-19T18:03:56.419-05:00","provider_id":8,"type":"Authorizations::Facebook","consumer_key":"EAA...","consumer_secret":null,"authorized_pages":[{"id":8,"authorization_id":7,"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=Nc8DGfaWQuAAX9j7fa8\u0026_nc_ht=scontent.xx\u0026_nc_tp=30\u0026oh=1c5b36b0f7975fe8a8bfd884cf6f31d8\u0026oe=605463E8","cover_id":"115550003469790","offset_x":50,"offset_y":38},"access_token":"EAA...","instagram_business_account":{"id":"17841421827949046"}},"created_at":"2021-02-19T18:03:56.682-05:00","updated_at":"2021-02-19T18:03:56.682-05:00"},{"id":9,"authorization_id":7,"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=Oelvv_4cSb4AX9hSuqN\u0026_nc_ht=scontent.xx\u0026oh=dedb18b14c0d52b8d4f6f3b4ad39301c\u0026oe=60540B4C"},"created_at":"2021-02-19T18:03:56.892-05:00","updated_at":"2021-02-19T18:03:56.892-05:00"}]}]}

After an Authorization has been created, we will automatically create AuthorizedPage records for the Authorization. An AuthorizedPage represents a social page that you’re allowed to post to via the Authorization. For an Instagram-connected Facebook page, there will be two AuthorizedPages (their Facebook page and Instagram page). Let’s use the Get All Authorized Pages endpoint to see our new Authorized Page records.

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

{"current_page":1,"per_page":30,"total_entries":2,"collection":[{"id":8,"authorization_id":7,"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=Nc8DGfaWQuAAX9j7fa8\u0026_nc_ht=scontent.xx\u0026_nc_tp=30\u0026oh=1c5b36b0f7975fe8a8bfd884cf6f31d8\u0026oe=605463E8","cover_id":"115550003469790","offset_x":50,"offset_y":38},"access_token":"EAA...","instagram_business_account":{"id":"17841421827949046"}},"created_at":"2021-02-19T18:03:56.682-05:00","updated_at":"2021-02-19T18:03:56.682-05:00"},{"id":9,"authorization_id":7,"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=Oelvv_4cSb4AX9hSuqN\u0026_nc_ht=scontent.xx\u0026oh=dedb18b14c0d52b8d4f6f3b4ad39301c\u0026oe=60540B4C"},"created_at":"2021-02-19T18:03:56.892-05:00","updated_at":"2021-02-19T18:03:56.892-05:00"}]}

Now that we have a Facebook AuthorizedPage record with an ID of 8 and an Instagram AuthorizedPage record with an ID of 9, we are ready to make a Post!