Post to facebook via cron

点点圈 提交于 2019-12-04 04:03:57

I was having a similar problem with the access token expiring. Turns out you can exchange your token to "long lived" token

Managed to dig up my code:

try{
        $token =  $facebook->getAccessToken();

        // get "long-lived" access token
        $curl = new Curl();
        $curl->setSsl();
        $exchange_url = "https://graph.facebook.com/oauth/access_token?client_id=".$facebook_app_id."&client_secret=".$facebook_app_secret."&grant_type=fb_exchange_token&fb_exchange_token=".$token;
        $page = $curl->get($exchange_url);

        if ($page){
            $page = explode("access_token=", $page);
            if (count($page) > 1){
                $page = explode("&", $page[1]);
                $token = $page[0];

                $facebook->setAccessToken($token);
            }
        }

    } catch(Exception $e){
        $token = '';
    }

They are other alternative you can use, for me i find it easier to use Twitter Api to post comment on twiiter and facebook at the same time. I linked it to Facebook, it works great all you will just have to do is change the twitter api key and supply data. If you are interested in this solution let me know and i will post the code here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!