need help on posting on user wall

前端 未结 1 400
不思量自难忘°
不思量自难忘° 2020-12-11 12:31

need help below is the code of index.php of my application and i want to Post on user wall after the user authorize my application with OFFLINE_ACCESS AND publish_stram

相关标签:
1条回答
  • 2020-12-11 13:13
    1. Download the Facebook PHP-SDK
    2. No need for the offline_access permission
    3. Get familiar with the PHP-SDK and use the code in the example page as your index, something like:

      <?php
      require '../src/facebook.php';
      $facebook = new Facebook(array(
        'appId'  => 'XXXXXXX',
        'secret' => 'XXXXXXXX',
        'cookie' => true,
      ));
      
      $session = $facebook->getSession();
      $loginUrl = $facebook->getLoginUrl(array(
          "req_perms" => "publish_stream"
      ));
      $me = null;
      
      if ($session) {
        try {
          $uid = $facebook->getUser();
          $me = $facebook->api('/me');
      
          echo "Welcome User: " . $me['name'] . "<br />";
      
          $post_id = $facebook->api("/$uid/feed", "post", array("message"=>"Hello World!"));
          if(isset($post_id))
              echo "A new post to your wall has been posted with id: $post_id";
      
        } catch (FacebookApiException $e) {
          error_log($e);
        }
      } else {
          echo("<script> top.location.href='" . $loginUrl . "'</script>");
      }
      ?>
      
    4. Welcome to Stackoverflow!
    0 讨论(0)
提交回复
热议问题