Posting to a Facebook Page as the Page (not a person)

前端 未结 1 1925
悲&欢浪女
悲&欢浪女 2020-12-05 15:14

I use Facebook PHP SDK 3.0.1 (latest currently). What I need to be able to do is to post as a the identity of the Page on the Page.

I tried replacing the access_toke

1条回答
  •  失恋的感觉
    2020-12-05 15:45

    1.First you have to get the page access token.

    public function getPageToken()
    {
    
        $page_id = "xxxxxxxxxx";
    
        $page_access_token = "";
    
    $result =  $this->facebook->api("/me/accounts");
    if( !empty($result['data']) )
    {
       foreach($result["data"] as $page) 
       {
         if($page["id"] == $page_id)
         {
           $page_access_token = $page["access_token"];
           break;
         }
       }
    }
    else
    {
      $url = "https://www.facebook.com/dialog/oauth?client_id=xxxxxxxxxx&redirect_uri=http://apps.facebook.com/xxxxxx&scope=manage_pages&response_type=token";
      echo "";
    }
    return $page_access_token;
    }
    

    2.After getting the page access token just include that token in your post to wall code.

    
    
    

    3.Remember this code will only publish your post on Fan page's wall and users who liked the fan page will be able to see that post as the post is posted on their own feed.

    Hope this will solve your problem.

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