SDKs
PHP SDK
Outfame API client for PHP 8.1+. Works standalone, with Laravel (auto-discovered service provider), or inside WordPress plugins. Built on Guzzle 7.x.
| Feature | Details |
|---|---|
| Package | outfame/outfame-php |
| Version | 1.5.0 |
| PHP | ≥ 8.1 |
| Dependencies | Guzzle 7.x, PSR-7 |
| License | MIT |
| Source | github.com/outfame/outfame-php |
Installation
composer require outfame/outfame-phpInitialization
Standalone
<?php
require_once 'vendor/autoload.php';
use Outfame\OutfameClient;
$outfame = new OutfameClient([
'api_key' => $_ENV['OUTFAME_API_KEY'],
]);Laravel integration
The SDK auto-registers its service provider. Add your API key to .env:
OUTFAME_API_KEY=sk_live_your_api_keyOptionally publish the config:
php artisan vendor:publish --tag=outfame-configInject the client from the container:
<?php
namespace App\Http\Controllers;
use Outfame\OutfameClient;
class GrowthController extends Controller
{
public function __construct(
private OutfameClient $outfame
) {}
public function dashboard(string $accountId)
{
$overview = $this->outfame->analytics()->overview($accountId, [
'period' => '30d',
]);
return view('growth.dashboard', [
'analytics' => $overview,
]);
}
}Accounts
<?php
// List accounts
$accounts = $outfame->accounts()->list([
'platform' => 'instagram',
'status' => 'active',
'limit' => 20,
]);
foreach ($accounts['data'] as $account) {
echo $account['id'] . ': ' . $account['instagram_username'] . PHP_EOL;
}
// Create account
$newAccount = $outfame->accounts()->create([
'instagram_username' => 'new_handle',
'platform' => 'instagram',
'targeting_config' => [
'competitor_accounts' => ['competitor1', 'competitor2'],
'hashtags' => ['fitness', 'wellness'],
'filters' => [
'age_range' => ['min' => 18, 'max' => 44],
'language' => 'en',
],
],
]);
// Retrieve
$account = $outfame->accounts()->retrieve('acc_7Gx2kLm9Qr');
// Update
$updated = $outfame->accounts()->update('acc_7Gx2kLm9Qr', [
'targeting_config' => [
'hashtags' => ['fitness', 'wellness', 'nutrition'],
],
]);
// Delete
$outfame->accounts()->delete('acc_7Gx2kLm9Qr');Analytics
<?php
// Overview
$overview = $outfame->analytics()->overview('acc_7Gx2kLm9Qr', [
'period' => '30d',
]);
echo "Net growth: +{$overview['net_growth']}" . PHP_EOL;
echo "Engagement rate: {$overview['engagement_rate']}%" . PHP_EOL;
// Growth time series
$growth = $outfame->analytics()->growth('acc_7Gx2kLm9Qr', [
'period' => '7d',
'granularity' => 'daily',
]);
foreach ($growth['data_points'] as $point) {
echo "{$point['date']}: {$point['followers']} (+{$point['net']})" . PHP_EOL;
}
// Audience demographics
$audience = $outfame->analytics()->audience('acc_7Gx2kLm9Qr');
echo "Quality score: {$audience['quality_score']}" . PHP_EOL;Targeting
<?php
// Get config
$config = $outfame->targeting()->config('acc_7Gx2kLm9Qr');
// Update
$outfame->targeting()->update('acc_7Gx2kLm9Qr', [
'competitor_accounts' => ['rival1', 'rival2'],
'hashtags' => ['travel', 'adventure'],
'ai_optimization' => [
'enabled' => true,
'mode' => 'balanced',
'quality_threshold' => 0.75,
],
]);
// AI suggestions
$suggestions = $outfame->targeting()->suggestions('acc_7Gx2kLm9Qr', [
'goal' => 'growth',
'include_reasoning' => true,
]);
echo "Confidence: {$suggestions['confidence']}" . PHP_EOL;Engagement
<?php
// Activity log
$activity = $outfame->engagement()->activity('acc_7Gx2kLm9Qr', [
'type' => 'like',
'limit' => 50,
]);
// Stats
$stats = $outfame->engagement()->stats('acc_7Gx2kLm9Qr');
echo "Likes: {$stats['actions']['likes']['performed']}/{$stats['actions']['likes']['limit']}" . PHP_EOL;
// Pause / Resume
$outfame->engagement()->pause('acc_7Gx2kLm9Qr', 'Content refresh');
$outfame->engagement()->resume('acc_7Gx2kLm9Qr');Webhooks
<?php
// Create
$webhook = $outfame->webhooks()->create([
'url' => 'https://yourapp.com/webhooks/outfame',
'events' => ['account.growth_milestone', 'engagement.daily_summary'],
]);
$signingSecret = $webhook['signing_secret']; // Store securely
// Verify signature
use Outfame\Webhook;
// Laravel route
Route::post('/webhooks/outfame', function (Request $request) {
$payload = $request->getContent();
$signature = $request->header('X-Outfame-Signature');
$timestamp = $request->header('X-Outfame-Timestamp');
if (!Webhook::verify($payload, $signature, $timestamp, config('outfame.webhook_secret'))) {
abort(401, 'Invalid webhook signature');
}
$event = json_decode($payload, true);
match ($event['type']) {
'account.growth_milestone' => handleMilestone($event['data']),
'engagement.daily_summary' => handleDailySummary($event['data']),
default => null,
};
return response()->json(['received' => true]);
});WordPress integration
For WordPress plugins, initialize the client in your plugin file:
<?php
/*
Plugin Name: My Outfame Integration
*/
require_once __DIR__ . '/vendor/autoload.php';
use Outfame\OutfameClient;
function get_outfame_client(): OutfameClient
{
static $client = null;
if ($client === null) {
$client = new OutfameClient([
'api_key' => get_option('outfame_api_key'),
]);
}
return $client;
}
// Example: Display growth stats in a shortcode
add_shortcode('outfame_growth', function ($atts) {
$atts = shortcode_atts(['account' => ''], $atts);
if (empty($atts['account'])) return '';
try {
$client = get_outfame_client();
$overview = $client->analytics()->overview($atts['account'], [
'period' => '30d',
]);
return sprintf(
'<div class="outfame-growth">+%d followers this month</div>',
$overview['net_growth']
);
} catch (\Exception $e) {
return '<div class="outfame-error">Unable to load growth data</div>';
}
});Error handling
<?php
use Outfame\Exceptions\OutfameException;
use Outfame\Exceptions\AuthenticationException;
use Outfame\Exceptions\RateLimitException;
use Outfame\Exceptions\NotFoundException;
use Outfame\Exceptions\ValidationException;
try {
$account = $outfame->accounts()->retrieve('acc_invalid');
} catch (NotFoundException $e) {
echo "Account not found: {$e->getMessage()}" . PHP_EOL;
} catch (RateLimitException $e) {
echo "Rate limited. Retry after {$e->getRetryAfter()}s" . PHP_EOL;
} catch (AuthenticationException $e) {
echo "Invalid API key" . PHP_EOL;
} catch (ValidationException $e) {
echo "Validation errors: " . json_encode($e->getErrors()) . PHP_EOL;
} catch (OutfameException $e) {
echo "API error ({$e->getErrorCode()}): {$e->getMessage()}" . PHP_EOL;
}Configuration
| Option | Type | Default | Description |
|---|---|---|---|
api_key | string | — | Your API key. |
access_token | string | null | OAuth access token. |
base_url | string | https://api.outfame.com/v1 | API base URL. |
timeout | int | 30 | Request timeout in seconds. |
max_retries | int | 3 | Automatic retries for transient errors. |
guzzle_options | array | [] | Additional Guzzle client options. |