Site icon Web Niraj

Facebook API: Adding Action Links to Posts

Action Links are a good way to add an extra call to action (CTA) beside the Link and Share links on Facebook Posts. The actions parameter lets you add a custom link and name to any post on Facebook, whether is a CTA to download a file, or voting in a poll / competition.

Action Links in PHP

The below code demonstrates a simple API call that adds a message with a custom “Search” action to the post. The name and link attributes inside of the actions parameter can be changed to say anything. And you can even add the other feed parameters like name, link, caption, picture and description to customise the post further.

See the gist on github.

The above code results in a post like:

Action Links in JavaScript

The below JavaScript example is a bit more elaborate, adding a link and related parameters to create a better post. The namelinkcaption, and picture attributes are used to add a link to the post.

See the gist on github.

The above code results in a share dialog like:

Demo

You can find a working example of the JavaScript code here. Click on the “Edit in JS Bin” button in the top-right corner to play around with the code too.

Exit mobile version