Search code examples
facebook-graph-apifacebook-marketing-api

How to get Facebook ad permalink using Facebook APi


When using ads manager, you can preview ad. There is also a hyperlink which goes View post permalink with comments. Is there any way to get that link using API


Solution

  • First you must get the creative that's targeted by the ad.

    $ad = new Ad($ad_id);
    $ad->read(array(
        AdFields::CREATIVE,
    ));
    

    Then get the info from the creative.

    $creative = new AdCreative($ad->creative['id']);
    $creative->read(array(
        AdCreativeFields::EFFECTIVE_OBJECT_STORY_ID,
    ));
    

    Then $creative->effective_object_story_id will contain an ID that would look like xxxxxxxxxxxxx_yyyyyyyyyyyyy, where x is the ID of the page, and y is the id of the post/video/etc. If you just go to https://facebook.com/xxxxxxxxxxxxx_yyyyyyyyyyyyy it should redirect you to the correct post

    Hope this helps someone.