Hybrid_Providers_Facebook::getUserActivity PHP Method

getUserActivity() public method

Load the user latest activity, needs 'read_stream' permission
public getUserActivity ( string $stream = 'timeline' )
$stream string Which activity to fetch: - timeline : all the stream - me : the user activity only {@inheritdoc}
    function getUserActivity($stream = 'timeline')
    {
        try {
            if ($stream == "me") {
                $response = $this->api->get('/me/feed', $this->token('access_token'));
            } else {
                $response = $this->api->get('/me/home', $this->token('access_token'));
            }
        } catch (FacebookSDKException $e) {
            throw new Hybrid_Exception("User activity stream request failed! {$this->providerId} returned an error: {$e->getMessage()}", 0, $e);
        }
        if (!$response || !count($response['data'])) {
            return [];
        }
        $activities = [];
        foreach ($response['data'] as $item) {
            $ua = new Hybrid_User_Activity();
            $ua->id = array_key_exists("id", $item) ? $item["id"] : "";
            $ua->date = array_key_exists("created_time", $item) ? strtotime($item["created_time"]) : "";
            if ($item["type"] == "video") {
                $ua->text = array_key_exists("link", $item) ? $item["link"] : "";
            }
            if ($item["type"] == "link") {
                $ua->text = array_key_exists("link", $item) ? $item["link"] : "";
            }
            if (empty($ua->text) && isset($item["story"])) {
                $ua->text = array_key_exists("link", $item) ? $item["link"] : "";
            }
            if (empty($ua->text) && isset($item["message"])) {
                $ua->text = array_key_exists("message", $item) ? $item["message"] : "";
            }
            if (!empty($ua->text)) {
                $ua->user->identifier = array_key_exists("id", $item["from"]) ? $item["from"]["id"] : "";
                $ua->user->displayName = array_key_exists("name", $item["from"]) ? $item["from"]["name"] : "";
                $ua->user->profileURL = "https://www.facebook.com/profile.php?id=" . $ua->user->identifier;
                $ua->user->photoURL = "https://graph.facebook.com/" . $ua->user->identifier . "/picture?type=square";
                $activities[] = $ua;
            }
        }
        return $activities;
    }