如何通过 CURL 将图像发布到 Facebook 页面的相册以及获取新的页面访问令牌?

How to publish an image to a Facebook Page's albums via CURL along with getting new Page Access Tokens?

目前,我有一个允许用户上传图片的网站,同时我希望将所有这些上传的图片自动发布到 Facebook 页面的相册中。我在下面使用了这个 CURL 代码:

    $args = array(
       'message' => $imageDescription,
        'access_token'=>$accesstoken,
        'url' => $img
    );

    $ch = curl_init();
    $url = 'https://graph.facebook.com/' . $albumid . '/photos';
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

    $data = curl_exec($ch);

    $response = json_decode($data,true);

根据我的测试,这段代码有效,但只能持续一个小时,因为我使用了从图 API 生成的访问令牌。 https://developers.facebook.com/docs/pages/access-tokens#expire 中提到了此过期。

我一直在 Stack Overflow 上四处寻找,大多数问题和答案都提到了使用应用程序 ID 和应用程序机密来生成新令牌,但是 这是一个页面而不是一个应用程序。没有app ID和app secret,卡死了

那么在这种情况下,我该怎么办?或者在这种情况下无法使用 CURL?

本例中的应用不是指游戏之类的东西,而是指 API 应用。这对于使用 OAuth 对用户进行身份验证的 API 来说很常见。您为您的帐户创建一个应用程序,它允许您使用您的用户帐户作为访问它的用户访问 Facebook API。

以下 post 解释了整个事情,甚至还提供了有关 facebook API 工作原理的信息 https://stormpath.com/blog/what-the-heck-is-oauth