Code Examples
Real-world code examples to help you integrate URI Social SDK into your application.
Quick Start - Generate Content for Multiple Platforms
Generate content for Instagram and Facebook simultaneously from a single seed description
import { URISocial } from '@urisocial/sdk';
const client = new URISocial({
apiKey: process.env.URISOCIAL_API_KEY
});
async function generatePost() {
const content = await client.content.generate({
seedContent: 'Hello from URI Social SDK! 🚀',
platforms: ['instagram', 'facebook'],
referenceImage: 'https://example.com/image.jpg'
});
console.log('Generated content:', content);
}
generatePost();React Integration
Using @urisocial/react's useContentGeneration hook to build a content generator form
import { useState } from 'react';
import { useContentGeneration } from '@urisocial/react';
export default function ContentGeneratorForm() {
const [seedContent, setSeedContent] = useState('');
const [platforms, setPlatforms] = useState(['instagram', 'facebook']);
const { content, isGenerating, error, generate } = useContentGeneration();
const handleSubmit = async (e) => {
e.preventDefault();
try {
await generate({ seedContent, platforms });
} catch {
// error is already available via the hook's "error" value
}
};
return (
<form onSubmit={handleSubmit} className="space-y-4">
<textarea
value={seedContent}
onChange={(e) => setSeedContent(e.target.value)}
placeholder="Describe what you want to generate..."
className="w-full p-3 border rounded"
rows={4}
/>
<div className="flex gap-2">
{['instagram', 'facebook', 'twitter', 'linkedin', 'tiktok'].map(platform => (
<label key={platform} className="flex items-center gap-2">
<input
type="checkbox"
checked={platforms.includes(platform)}
onChange={(e) => {
if (e.target.checked) {
setPlatforms([...platforms, platform]);
} else {
setPlatforms(platforms.filter(p => p !== platform));
}
}}
/>
{platform}
</label>
))}
</div>
<button
type="submit"
disabled={isGenerating || !seedContent}
className="px-4 py-2 bg-pink-600 text-white rounded disabled:opacity-50"
>
{isGenerating ? 'Generating...' : 'Generate Content'}
</button>
{error && <p className="text-red-600">Error: {error.message}</p>}
{content && <pre className="text-sm bg-gray-50 p-3 rounded">{JSON.stringify(content, null, 2)}</pre>}
</form>
);
}More Examples
Full Example Repository
Check out the SDK's GitHub repository for the source code, its own example projects, and full API types.
View on GitHub