简体   繁体   English

使用PHP SDK 4获取Facebook页面的最后5篇帖子

[英]Get last 5 posts of a facebook page using PHP SDK 4

I want to get last 5 post post of a page using PHP SDK 4. I have tired to initial this way 我希望使用PHP SDK 4获得页面的最后5篇帖子。我已经厌倦了这种方式

<?php
    session_start();
    // added in v4.0.0
    require_once 'autoload.php';
    use Facebook\FacebookSession;
    use Facebook\FacebookRedirectLoginHelper;
    use Facebook\FacebookRequest;
    use Facebook\FacebookResponse;
    use Facebook\FacebookSDKException;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookAuthorizationException;
    use Facebook\GraphObject;
    use Facebook\Entities\AccessToken;
    use Facebook\HttpClients\FacebookCurlHttpClient;
    use Facebook\HttpClients\FacebookHttpable;

    FacebookSession::setDefaultApplication( 'app_id','app_secret' );
    $session = new FacebookSession('access_token');

    $request = new FacebookRequest(
      $session,
      'GET',
      'page_id'
    );
    $response = $request->execute();
    $graphObject = $response->getGraphObject();
?>

How i can find ACCESS TOKEN And get the recent post? 我怎么能找到ACCESS TOKEN并获得最近的帖子?

You can use an App Acess Token for that: 您可以使用App Acess令牌:

$access_token = APPID . '|' . APPSECRET;

...but you don´t need to generate it on your own, i think you just need to do a call to the feed endpoint - and include the limit to only get the last 5 entries: ...但你不需要自己生成它,我认为你只需要调用feed端点 - 并包含限制只能获得最后5个条目:

$request = new FacebookRequest(
    $session,
    'GET',
    '/page_id/feed?limit=5'
);

Source: https://developers.facebook.com/docs/graph-api/reference/v2.1/page/feed 资料来源: https//developers.facebook.com/docs/graph-api/reference/v2.1/page/feed

Without user authorization, the SDK should use an App Access Token. 如果没有用户授权,SDK应使用App Access Token。 Keep in mind that this will only work for published Pages. 请记住,这仅适用于已发布的页面。 Unpublished Pages can only be read with a Page Token (or a User Token of a Page Admin). 未发布的页面只能使用页面令牌(或页面管理员的用户令牌)读取。 And some Pages are age or country restricted, you can´t use an App Token for them either. 有些页面受年龄或国家限制,您也无法使用App令牌。

You can also obtain your access token like this: 您还可以像这样获取访问令牌:

$session = FacebookSession::newAppSession();    
$access_token = $session->getAccessToken();
$session = new FacebookSession($access_token);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM