Publish Facebook POST Using API not Considering OG Meta Tags

113 views Asked by At

in my website i save the new pages & automatically publish that page in in my facebook page using this facebook link, but after publish if i want to normally share this post and put the url i get no title or image or .. when i go to facebook Open Graph Object Debugger and enter that url i realize that it doesn't read the og tags, but if i click "Fetch new scrape information" it get the information from og tags correctly. what is the problem and how can i solve it?

below is the PHP code function i used:

function facebook_post($fb_data) {
    $config = array('appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET);
    $fb = new Facebook($config);
    $fb->setAccessToken(FACEBOOK_ACCESS_TOKEN);
    $post_access_token = FACEBOOK_ACCESS_TOKEN;
    $page_info = $fb->api("/" . FACEBOOK_PAGE_ID . "/?fields=access_token", 'GET', array('access_token' => FACEBOOK_ACCESS_TOKEN));
    $post_access_token = $page_info['access_token'];
    //
    $params = array(
        "access_token" => $post_access_token
        //, "message" => $fb_data['facebook_message']
        , "link" => $fb_data['facebook_url']
        , "picture" => $fb_data['facebook_image']
        , "name" => $fb_data['facebook_title']
        //, "caption" => $fb_data['facebook_caption']
        , "description" => ($fb_data['facebook_description'] ? $fb_data['facebook_description'] : '')
        //, "published" => true
    );
    // post to Facebook : https://developers.facebook.com/docs/reference/php/facebook-api/
    try {
        $ret = $fb->api('/me/feed', 'POST', $params);
//        $post_id = $ret['id'];
        return true;
    } catch (Exception $e) {
        return false;
    }
}

Thanks.

0

There are 0 answers