Get Player Feed
Retrieve social feed data for a specific app, including player posts, achievements, tournament results, and other social activities.
Method
getFeedData(string $appID, array $feedType, string $reqPlayerID = '', int $maxResults = 25, int $loadedCount = 0, int $postsBy = Constants::FEED_POST_BY_ALL, array $loadedLeaderboardIDs = [], array $loadedTournamentIDs = []): array
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$appID | string | Yes | The app ID for which to fetch the feed |
$feedType | array | Yes | Array of feed types to fetch (see Feed Types below) |
$reqPlayerID | string | No | Player ID from whose perspective to load feed (default: empty) |
$maxResults | int | No | Maximum number of feed items to fetch (default: 25) |
$loadedCount | int | No | Number of feeds already loaded for pagination (default: 0) |
$postsBy | int | No | Filter posts by source (default: FEED_POST_BY_ALL) |
$loadedLeaderboardIDs | array | No | Leaderboard IDs to exclude from results |
$loadedTournamentIDs | array | No | Tournament IDs to exclude from results |
Feed Types
Use these constants with $feedType parameter:
| Constant | Value | Description |
|---|---|---|
Constants::FEED_TYPE_BEAT_SCORE | 0 | Score beating achievements |
Constants::FEED_TYPE_HIGH_SCORE | 1 | High score achievements |
Constants::FEED_TYPE_POST_ALL | 2 | All types of posts |
Constants::FEED_TYPE_POST_TEXT_ONLY | 3 | Text-only posts |
Constants::FEED_TYPE_POST_IMAGE_ONLY | 4 | Image-only posts |
Constants::FEED_TYPE_POST_VIDEO_ONLY | 5 | Video-only posts |
Constants::FEED_TYPE_LEADEBOARD | 7 | Leaderboard-related posts |
Constants::FEED_TYPE_TOURNAMENT | 8 | Tournament-related posts |
Constants::FEED_TYPE_FEATURED | 9 | Featured content |
Post Filters
Use these constants with $postsBy parameter:
| Constant | Value | Description |
|---|---|---|
Constants::FEED_POST_BY_REQUESTING_PLAYER | 0 | Posts by the requesting player only |
Constants::FEED_POST_BY_FRIENDS | 1 | Posts by friends only |
Constants::FEED_POST_BY_ALL | 2 | Posts by all players (default) |
Return Value
Returns an array with the following structure:
[
'players' => Player[], // Array of Player objects
'data' => FeedItem[] // Array of FeedItem objects
]
Example Usage
Basic Feed Retrieval
use Veniso\Moitribe\Sdk\MoitribeApi;
use Veniso\Moitribe\Sdk\modules\classes\Constants;
$moitribe = new MoitribeApi(['apiKey' => 'your-api-key']);
// Get all types of feed posts for an app
$feedTypes = [
Constants::FEED_TYPE_POST_ALL,
Constants::FEED_TYPE_TOURNAMENT,
Constants::FEED_TYPE_LEADEBOARD
];
$feedData = $moitribe->feeds()->getFeedData(
'your-app-id',
$feedTypes
);
foreach ($feedData['data'] as $feedItem) {
echo "Feed ID: " . $feedItem->getId() . "\n";
echo "Type: " . $feedItem->getType() . "\n";
echo "Content: " . $feedItem->getText() . "\n";
echo "Timestamp: " . $feedItem->getTimestamp() . "\n";
echo "---\n";
}
Player-Specific Feed
// Get feed from player's perspective
$feedData = $moitribe->feeds()->getFeedData(
'your-app-id',
[Constants::FEED_TYPE_POST_ALL],
'player-123', // Requesting player ID
20, // Max results
0, // Loaded count
Constants::FEED_POST_BY_FRIENDS // Only friends' posts
);
Paginated Feed Loading
function loadFeedPaginated($moitribe, $appId, $page = 0, $pageSize = 25) {
$feedTypes = [Constants::FEED_TYPE_POST_ALL];
$loadedCount = $page * $pageSize;
$feedData = $moitribe->feeds()->getFeedData(
$appId,
$feedTypes,
'', // No specific player perspective
$pageSize, // Max results
$loadedCount // Already loaded count
);
return $feedData;
}
// Load first page
$page1 = loadFeedPaginated($moitribe, 'your-app-id', 0, 25);
// Load second page
$page2 = loadFeedPaginated($moitribe, 'your-app-id', 1, 25);
Tournament and Leaderboard Feed Only
// Get only tournament and leaderboard related posts
$tournamentFeed = $moitribe->feeds()->getFeedData(
'your-app-id',
[
Constants::FEED_TYPE_TOURNAMENT,
Constants::FEED_TYPE_LEADEBOARD
],
'', // All players
50, // More results for competitive content
0, // Start from beginning
Constants::FEED_POST_BY_ALL
);
Feed with Exclusions
// Exclude already seen tournaments and leaderboards
$excludedTournaments = ['tourn-1', 'tourn-2'];
$excludedLeaderboards = ['ldr-1'];
$feedData = $moitribe->feeds()->getFeedData(
'your-app-id',
[Constants::FEED_TYPE_POST_ALL],
'',
25,
0,
Constants::FEED_POST_BY_ALL,
$excludedLeaderboards,
$excludedTournaments
);
Error Handling
try {
$feedData = $moitribe->feeds()->getFeedData(
'your-app-id',
[Constants::FEED_TYPE_POST_ALL]
);
if (empty($feedData['data'])) {
echo "No feed items found\n";
} else {
echo "Found " . count($feedData['data']) . " feed items\n";
}
} catch (InvalidArgumentException $e) {
echo "Invalid argument: " . $e->getMessage() . "\n";
} catch (Exception $e) {
echo "Error fetching feed: " . $e->getMessage() . "\n";
}
Integration Examples
Web API Endpoint
// routes/web.php
use Illuminate\Http\Request;
Route::get('/api/feed/{appId}', function (Request $request, $appId) {
$moitribe = new MoitribeApi(['apiKey' => config('moitribe.api_key')]);
$feedTypes = $request->input('types', [
Constants::FEED_TYPE_POST_ALL,
Constants::FEED_TYPE_TOURNAMENT
]);
$playerId = $request->input('player_id', '');
$maxResults = $request->input('limit', 25);
$page = $request->input('page', 0);
try {
$feedData = $moitribe->feeds()->getFeedData(
$appId,
$feedTypes,
$playerId,
$maxResults,
$page * $maxResults
);
return response()->json([
'success' => true,
'data' => $feedData['data'],
'players' => $feedData['players'],
'pagination' => [
'page' => $page,
'limit' => $maxResults,
'has_more' => count($feedData['data']) >= $maxResults
]
]);
} catch (Exception $e) {
return response()->json([
'success' => false,
'error' => $e->getMessage()
], 500);
}
});
Real-time Feed Updates
class FeedService {
private $moitribe;
private $cache;
public function __construct($moitribe, $cache) {
$this->moitribe = $moitribe;
$this->cache = $cache;
}
public function getFreshFeed($appId, $playerId = '') {
$cacheKey = "feed:{$appId}:" . ($playerId ?: 'global');
// Try to get from cache first
$cachedFeed = $this->cache->get($cacheKey);
if ($cachedFeed) {
return $cachedFeed;
}
// Fetch fresh data
$feedData = $this->moitribe->feeds()->getFeedData(
$appId,
[Constants::FEED_TYPE_POST_ALL],
$playerId,
50
);
// Cache for 5 minutes
$this->cache->set($cacheKey, $feedData, 300);
return $feedData;
}
public function invalidateFeedCache($appId, $playerId = '') {
$cacheKey = "feed:{$appId}:" . ($playerId ?: 'global');
$this->cache->delete($cacheKey);
}
}
Best Practices
- Pagination: Use
$loadedCountand$maxResultsfor efficient pagination - Filtering: Specify only the feed types you need to reduce response size
- Caching: Cache feed data for short periods to improve performance
- Player Context: Use
$reqPlayerIDto personalize feed content - Exclusions: Use
$loadedLeaderboardIDsand$loadedTournamentIDsto avoid duplicates
Related Methods
- Feed Comments - Comment on feed items, load comments, and like/unlike feed items
Feed Item Structure
Each FeedItem in the response contains:
id- Unique feed item identifiertype- Type of feed contenttext- Text content of the posttimestamp- When the item was createdplayerId- ID of the player who created itlikes- Number of likescomments- Number of comments- Additional metadata based on feed type
Player Data Structure
The players array contains Player objects for all players referenced in the feed, allowing you to display player information without additional API calls.