Get list of Page Albums using Facebook PHP SDK v5

前端 未结 1 1395
耶瑟儿~
耶瑟儿~ 2021-01-02 23:42

I want to use Facebook PHP SDK v5 to get a list of photo albums for a Page.

I am following the instructions at https://developers.facebook.com/docs/graph-ap

相关标签:
1条回答
  • 2021-01-03 00:22

    Have a look at the docs at

    • https://developers.facebook.com/docs/php/FacebookRequest/5.0.0#overview
    • https://developers.facebook.com/docs/php/gettingstarted/5.0.0#making-requests

    Sample code:

    $fbApp = new Facebook\FacebookApp('{app-id}', '{app-secret}');
    $request = new Facebook\FacebookRequest($fbApp, '{access-token}', 'GET', '/{page_id}/albums');
    
    // OR
    
    $fb = new Facebook\Facebook(/* . . . */);
    $request = $fb->request('GET', '/{page_id}/albums');
    
    // Send the request to Graph
    try {
      $response = $fb->getClient()->sendRequest($request);
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      // When Graph returns an error
      echo 'Graph returned an error: ' . $e->getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      // When validation fails or other local issues
      echo 'Facebook SDK returned an error: ' . $e->getMessage();
      exit;
    }
    
    $graphNode = $response->getGraphNode();
    
    print_r($graphNode);
    
    0 讨论(0)
提交回复
热议问题