SDK Installation & Quick Start
Integrate the ConnectHub SDK into your application to access the full power of the social platform. Create posts, manage communities, stream live content, and interact with users programmatically.
Installation
Install the ConnectHub SDK using your preferred package manager. We support JavaScript/TypeScript, Python, Swift, and Kotlin.
npm install @connecthub/sdk
For TypeScript users, types are included automatically.
pip install connecthub-sdk
package.dependencies.append(
.package(url: "https://github.com/connecthub/sdk-swift.git", from: "2.4.0")
)
implementation("com.connecthub:sdk-kotlin:2.4.0")
Quick Start
Get up and running in less than a minute. Initialize the client with your API key and make your first request.
import { ConnectHub } from '@connecthub/sdk'; // Initialize the client const hub = new ConnectHub({ apiKey: process.env.CONNECTHUB_API_KEY, environment: 'production' // or 'sandbox'}); // Fetch authenticated user profile async function getUser() { try { const user = await hub.users.get('me'); console.log(`Logged in as: ${user.username}`); console.log(`Followers: ${user.stats.followers}`); } catch (error) { console.error('Failed to fetch user', error); } } getUser();
import connecthub # Initialize the client hub = connecthub.Client( api_key=os.environ["CONNECTHUB_API_KEY"], environment="production" ) # Fetch authenticated user profile try: user = hub.users.get("me") print(f"Logged in as: {user.username}") print(f"Followers: {user.stats.followers}") except connecthub.AuthenticationError: print("Invalid API key")
Creating Content
Use the SDK to publish posts, stories, and media to your profile or on behalf of a community.
Create a new post with text, media, and engagement settings.
| Parameter | Type | Description |
|---|---|---|
| body Required | String | The text content of the post (max 280 chars) |
| media_ids | String[] | Array of uploaded media IDs |
| visibility | Enum | public, followers, or private |
| community_id | String | Post to a specific community instead of personal profile |
// Create a post with an image const post = await hub.posts.create({ body: 'Just launched our new feature! đ @connecthub', media_ids: ['img_8x92js'], visibility: 'public', tags: ['launch', 'connecthub'] }); console.log(`Post created: ${post.id}`);
# Create a post with an image post = hub.posts.create( body="Just launched our new feature! đ @connecthub", media_ids=["img_8x92js"], visibility="public", tags=["launch", "connecthub"] ) print(f"Post created: {post.id}")
Error Handling
The SDK throws typed errors to help you handle failures gracefully. Always wrap async calls in try-catch blocks.
const { ConnectHubError } = require('@connecthub/sdk/errors'); try { await hub.posts.create({ body: 'Hello' }); } catch (error) { if (error instanceof ConnectHubError) { console.log(`Error code: ${error.code}`); console.log(`Message: ${error.message}`); if (error.code === 'RATE_LIMITED') { // Implement backoff strategy } } }