Facebook post on page with PHP SDK

后端 未结 2 858
囚心锁ツ
囚心锁ツ 2021-01-02 23:06

I\'d like to post on page - throught my site. . I didn\'t find anything that could help me in documentation. Also none of google results gave mi answer.

func         


        
相关标签:
2条回答
  • 2021-01-02 23:17

    if you want to post on a fan page where you are adminstrator.. do the next

    1. Your application needs to have this permission minimum:

          $this->loginUrl = $this->facebook->getLoginUrl(
                array(
                      'scope'         => 'manage_pages,offline_access,publish_stream',
                      'redirect_uri'  => $url,
                  )
          );
      
    2. After you are logged into:

      //get pages or applications where you are administrator
      $accounts = $this->facebook->api('/me/accounts');
      
      //page where i want to post
      $page_id = '227870047252297';
      
      foreach($accounts['data'] as $account)
      {
         if($account['id'] == $page_id)
         {
            $token = $account['access_token'];
         }
      }
      
      
      $attachment = array(
              'access_token' => $token,
              'message' => 'mensaje',
              'name' => 'titulo',
              'link' => 'http://...',
              'description' => 'xxxxx',
              'picture'=> 'http://...',
      );
      
      
      try{
      $res = $this->facebook->api('/'.$page_id.'/feed','POST',$attachment);
      
      } catch (Exception $e){
      
          echo $e->getMessage();
      }
      
    0 讨论(0)
  • 2021-01-02 23:26

    If I understand this correctly, you want to send a message to the user's wall who's connected to your application via your website the moment they log in? If so, try this. Rework the script to prevent constant posting, but this model, in theory, should work.

    if ($session) {
            try {
                $uid = $facebook->getUser();
                $me = $facebook->api('/me');
    

    // Place messaging portion here instead.

        $message = $facebook->api('/me/feed', 'post', array(
                                                                 'message'=> '<Message>', 
                                                                 'picture' => '<Picture URL>', 
                                                                 'link'=> '<URL>',
                                                                 'description'=>'Description', 
                                                                 'name'=> '<Name of Post>', 
                                                                 'privacy'=> '<ALL_FRIENDS (Default)>',
                                                                 'caption'=> '<Caption>',                                                           
    
                                                                 )
                                       );
    
                } catch (FacebookApiException $e) {
                    error_log($e);
                }
    

    So if the user is connected with your application and the session is valid, it will automatically send the post to their news feed (Wall).

    0 讨论(0)
提交回复
热议问题