没有让Facebook应用程序发布到Page's Wall,就像那个页面

时间:2017-10-02 07:38:00

标签: php facebook facebook-graph-api

我正在努力围绕圈子让Facebook应用程序发布到Page's Wall,就像那个页面一样。

** Note: I put out a 300 point bounty to update an outdated answer of a related, well-viewed, existing question. Happy to award anyone who also answers there with the updated, working, solution

简而言之:

  1. 我有App Secret和ID
  2. 我有网页ID
  3. 我依靠内嵌代码方法来生成我需要的令牌。
  4. 它基于我在SDK GitHub页面上发布的解决方案,但它不起作用
  5. 我使用的是API v 2.9
  6. 我使用的是最新的PHP SDK
  7. 这很难。

    我使用的解决方案完全基于下面的解决方案:

    <?php
    define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__ . '/Facebook');
    require_once __DIR__ . '/Facebook/autoload.php';
    
    use Facebook\FacebookRequest;
    
    $app_id = {{your app-id}};
    $app_secret = {{your app-secret}};
    
    $fb = new Facebook\Facebook([
      'app_id' => $app_id,
      'app_secret' => $app_secret,
      'default_graph_version' => '{{your app-version}}', 
      ]);
    
    $token = $fb->get(
        '/oauth/access_token?client_id=' . $app_id . '&'.
        'client_secret=' . $app_secret . '&'.
        'grant_type=client_credentials');
    
    $get_token = $token -> getdecodedBody();
    $access_token = $get_token['access_token'];
    
    try {
      // Returns a `Facebook\FacebookResponse` object
      $response = $fb->get('/{{your facebook name}}', $access_token);
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e->getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e->getMessage();
      exit;
    }
    
    $body = $response->getBody();
    
    print_r($body);
    ?>
    

    我当然不是懒惰。几个星期以来,我一直坚持这个问题。

    我尝试了以下不同的解决方案,并且遇到了与权限相关的问题,这个问题也与depracated功能和API调用相关,或者获得了正确的令牌。

    1. Posting to a facebook page from a website using curl(使用纯CURL方法 - “用户未授权应用程序执行此操作”)
    2. Facebook SDK returned an error: You must provide an access token. Php Facebook Api - (建议我支持登录和重定向回调 - 但是每次发布到页面时我都不希望任何用户干预)
    3. Graph returned an error: Invalid appsecret_proof provided in the API argument - 之前的尝试是基于此示例,但是基于appsecret-proof的问题
    4. Simple example to post to a Facebook fan page via PHP? - 另一种基于CURL的方法让我失望
    5. https://stackoverflow.com/a/14212125/919426 - 最佳解释一步一步 权限和令牌的步骤过程,但仍然失败
    6. 更新: 尝试以下操作并得到错误"Invalid appsecret_proof provided in the API argument"

      $fb = new Facebook([
          'app_id' => 'APP_ID',
          'app_secret' => 'APP_SECRET',
          'default_graph_version' => 'v2.9',
      ]);
      
      $postData = [
          'message' => "Test Message",
          'picture' => 'https://www.website.com/image.jpg'
      ];
      
      try
      {
          // 'LONG_LIVED_PAGE_ACCESS_TOKEN' obtained by going to https://developers.facebook.com/tools/debug/accesstoken and clicking
          // "Extend Access Token"
          $response = $fb->post('/' . 'PAGE_ID' . '/feed', $postData,"LONG_LIVED_PAGE_ACCESS_TOKEN");
      }
      catch (FacebookResponseException $e)
      {
          var_dump("Facebook Response Exception occured: \n" . $e);
          exit;
      }
      catch(FacebookSDKException $e)
      {
          var_dump("Generic Facebook SDK Exception occured: \n" . $e);
          exit;
      }
      catch(Exception $e)
      {
          var_dump("Uknown Exception occured while attempting to call the Facebook SDK API: \n" . $e);
          exit;
      }
      

      我尝试过多次失败。

0 个答案:

没有答案
相关问题