承接 storygrab/php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

storygrab/php-sdk

Composer 安装命令:

composer require storygrab/php-sdk

包简介

Official PHP SDK for the StoryGrab API – Partner & Mobile APIs

README 文档

README

PHP Version License

Official PHP SDK for the StoryGrab API.
Covers both the Partner API (for third-party integrations) and the Mobile API (for user-facing apps).

Requirements

Requirement Version
PHP ^8.1
Guzzle ^7.0

Installation

composer require storygrab/php-sdk

Quick Start

Partner API

use StoryGrab\StoryGrabClient;

$client = StoryGrabClient::partner(
    apiToken: 'YOUR_PARTNER_API_TOKEN',
    baseUrl:  'https://app.storygrab.io'  // optional, defaults to this
);

// List all authorized profiles
$profiles = $client->partner()->profiles();
foreach ($profiles as $profile) {
    echo $profile->username . PHP_EOL;
}

// Get a single profile
$profile = $client->partner()->profile('nasa');

// Get paginated posts for a profile
$page = $client->partner()->profilePosts('nasa', perPage: 50);
foreach ($page->data as $post) {
    echo $post->shortcode . '' . $post->caption . PHP_EOL;
}

// Next page
if ($page->hasMorePages()) {
    $nextPage = $client->partner()->profilePosts('nasa', perPage: 50, page: 2);
}

// All posts across every authorized profile
$posts = $client->partner()->posts(perPage: 30, page: 1);

// Latest stories (up to 50)
$stories = $client->partner()->latestStories(limit: 20);

// Create a video embed
$embed = $client->partner()->createVideoEmbed(
    videoUrl:   'https://cdn.example.com/video.mp4',
    expiresIn:  3600  // 1 hour
);
echo $embed->embedUrl; // https://app.storygrab.io/embed/v/<token>

Mobile API

use StoryGrab\StoryGrabClient;

$client = StoryGrabClient::mobile('https://app.storygrab.io');

// Authenticate (token is automatically applied to subsequent requests)
$auth = $client->mobile()->login(
    email:      'user@example.com',
    password:   'secret',
    deviceName: 'my-app-v1'
);
echo 'Logged in as: ' . $auth->user->name;

// Register a new account
$auth = $client->mobile()->register(
    name:            'Ada Lovelace',
    email:           'ada@example.com',
    password:        'secure-pass',
    passwordConfirm: 'secure-pass',
    deviceName:      'my-app'
);

// Get the authenticated user's profile
$user = $client->mobile()->user();

// Paginated feed
$feed = $client->mobile()->feed(perPage: 20);
foreach ($feed->data as $post) {
    echo $post->caption . PHP_EOL;
}

// Latest stories
$stories = $client->mobile()->stories(limit: 30);

// Search
$results = $client->mobile()->search('space telescope');
// $results['profiles'] => Profile[]
// $results['posts']    => Post[]

// Bookmarks
$bookmarks = $client->mobile()->bookmarks();

// Toggle bookmark
$status = $client->mobile()->toggleBookmark('post-ulid-here');
// 'added' | 'removed'

// Logout
$client->mobile()->logout();

Error Handling

All SDK methods throw typed exceptions on non-2xx responses:

Exception HTTP Status
AuthenticationException 401, 403
NotFoundException 404
ValidationException 422
RateLimitException 429
ApiException (base) all other errors
use StoryGrab\Exceptions\AuthenticationException;
use StoryGrab\Exceptions\NotFoundException;
use StoryGrab\Exceptions\ValidationException;
use StoryGrab\Exceptions\RateLimitException;
use StoryGrab\Exceptions\ApiException;

try {
    $profile = $client->partner()->profile('unknown-handle');
} catch (NotFoundException $e) {
    echo 'Profile not found: ' . $e->getMessage();
} catch (AuthenticationException $e) {
    echo 'Invalid or expired token.';
} catch (ValidationException $e) {
    // Field-level errors as ['field' => ['error message', ...]]
    print_r($e->getErrors());
} catch (RateLimitException $e) {
    echo 'Slow down! Retry after a moment.';
} catch (ApiException $e) {
    echo 'API error ' . $e->getStatusCode() . ': ' . $e->getMessage();
}

Data Objects

All responses are returned as immutable typed DTOs (PHP 8.1 readonly properties):

Class Description
Profile An Instagram profile
Post An archived Instagram post (with media: Media[])
Story An archived Instagram story (with media: Media[])
Media A single media item (image or video) within a post/story
EmbedTemplate A partner HTML/CSS/JS embed template
VideoEmbed A generated embed token + URL
AuthResponse Token + User returned on login/register
User An authenticated mobile user
PaginatedResponse<T> Generic paginator wrapper with data, currentPage, lastPage, total, etc.

Advanced Usage

Paginating through all pages

$page    = 1;
$allPosts = [];

do {
    $result   = $client->partner()->posts(perPage: 100, page: $page);
    $allPosts = array_merge($allPosts, $result->data);
    $page++;
} while ($result->hasMorePages());

Fetching everything at once (per_page=all)

$all = $client->partner()->profilePosts('nasa', perPage: 'all');

Using a custom Guzzle client

use GuzzleHttp\Client;
use StoryGrab\StoryGrabClient;

$http   = new Client(['base_uri' => 'https://my-proxy.example.com/api/v1/partner/', 'timeout' => 60]);
$client = StoryGrabClient::withHttpClient($http);

Swapping the token at runtime

$client->setToken('new-token-after-rotation');

Running Tests

composer install
composer test

License

MIT © StoryGrab

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固