@olastudio/social-media-sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -51
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -2,109 +2,244 @@
|
|
|
2
2
|
|
|
3
3
|
Modular SDK for managing authentication and APIs of multiple social media platforms.
|
|
4
4
|
|
|
5
|
-
**Works everywhere:**
|
|
6
|
-
- Node.js
|
|
7
|
-
- Deno (Supabase Edge Functions)
|
|
8
|
-
- Browser
|
|
9
|
-
- React Native / Expo
|
|
10
|
-
|
|
11
5
|
## Installation
|
|
12
6
|
|
|
13
7
|
```bash
|
|
14
8
|
npm install @olastudio/social-media-sdk
|
|
15
9
|
```
|
|
16
10
|
|
|
11
|
+
## Supported Platforms
|
|
12
|
+
|
|
13
|
+
- **Facebook** - Pages management, posts publishing, insights
|
|
14
|
+
- **Instagram** - Account insights, media management, content publishing
|
|
15
|
+
- **TikTok** - User info, video list, account insights, content publishing
|
|
16
|
+
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
|
-
###
|
|
19
|
+
### Initialize Providers
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import { FacebookProvider, InstagramProvider } from '@olastudio/social-media-sdk';
|
|
22
|
+
import { FacebookProvider, InstagramProvider, TikTokProvider } from '@olastudio/social-media-sdk';
|
|
23
23
|
|
|
24
|
-
//
|
|
24
|
+
// Facebook
|
|
25
25
|
const facebookProvider = new FacebookProvider({
|
|
26
|
-
appId:
|
|
26
|
+
appId: 'YOUR_FACEBOOK_APP_ID',
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
+
// Instagram
|
|
29
30
|
const instagramProvider = new InstagramProvider({
|
|
30
|
-
appId:
|
|
31
|
+
appId: 'YOUR_FACEBOOK_APP_ID', // Instagram uses Facebook App ID
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// TikTok
|
|
35
|
+
const tiktokProvider = new TikTokProvider({
|
|
36
|
+
clientKey: 'YOUR_TIKTOK_CLIENT_KEY',
|
|
31
37
|
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Set Access Token
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
```typescript
|
|
43
|
+
// After obtaining user's access token via OAuth
|
|
34
44
|
facebookProvider.setAccessToken(userAccessToken);
|
|
35
45
|
instagramProvider.setAccessToken(userAccessToken);
|
|
46
|
+
tiktokProvider.setAccessToken(userAccessToken);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Facebook API
|
|
50
|
+
|
|
51
|
+
### Get User Pages
|
|
36
52
|
|
|
37
|
-
|
|
53
|
+
```typescript
|
|
38
54
|
const pages = await facebookProvider.api.getPages();
|
|
55
|
+
console.log('User pages:', pages);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Get Page Insights
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const insights = await facebookProvider.api.getPageInsights(pageId, {
|
|
62
|
+
metric: ['page_impressions', 'page_engaged_users'],
|
|
63
|
+
period: 'day',
|
|
64
|
+
since: startTimestamp,
|
|
65
|
+
until: endTimestamp,
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Publish Post
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// Text only
|
|
73
|
+
const post = await facebookProvider.api.publishPost({
|
|
74
|
+
pageId: 'PAGE_ID',
|
|
75
|
+
pageAccessToken: 'PAGE_ACCESS_TOKEN',
|
|
76
|
+
message: 'Hello from the SDK!',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// With photo
|
|
80
|
+
const photoPost = await facebookProvider.api.publishPost({
|
|
81
|
+
pageId: 'PAGE_ID',
|
|
82
|
+
pageAccessToken: 'PAGE_ACCESS_TOKEN',
|
|
83
|
+
message: 'Check out this photo!',
|
|
84
|
+
imageUrl: 'https://example.com/photo.jpg',
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Get Fan Count
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const fansData = await facebookProvider.api.getPageFansCount(pageId);
|
|
92
|
+
console.log('Fans:', fansData.fan_count);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Instagram API
|
|
96
|
+
|
|
97
|
+
### Get Account Info
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const account = await instagramProvider.api.getAccount(accountId);
|
|
101
|
+
console.log('Account:', account);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Get Account Insights
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
39
107
|
const insights = await instagramProvider.api.getAccountInsights(accountId, {
|
|
40
|
-
metric: ['reach', 'impressions'],
|
|
108
|
+
metric: ['reach', 'impressions', 'profile_views'],
|
|
41
109
|
period: 'day',
|
|
42
110
|
since: startTimestamp,
|
|
43
111
|
until: endTimestamp,
|
|
44
112
|
});
|
|
45
113
|
```
|
|
46
114
|
|
|
47
|
-
###
|
|
115
|
+
### Get Media
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const media = await instagramProvider.api.getMedia(accountId, 25);
|
|
119
|
+
console.log('Recent media:', media);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Publish Photo
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const post = await instagramProvider.api.publishPhoto({
|
|
126
|
+
instagramAccountId: 'IG_ACCOUNT_ID',
|
|
127
|
+
imageUrl: 'https://example.com/photo.jpg',
|
|
128
|
+
caption: 'Hello Instagram!',
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Publish Reel
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const reel = await instagramProvider.api.publishReel({
|
|
136
|
+
instagramAccountId: 'IG_ACCOUNT_ID',
|
|
137
|
+
videoUrl: 'https://example.com/video.mp4',
|
|
138
|
+
caption: 'My new reel!',
|
|
139
|
+
coverUrl: 'https://example.com/cover.jpg',
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## TikTok API
|
|
144
|
+
|
|
145
|
+
### Get User Info
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const userInfo = await tiktokProvider.api.getUserInfo();
|
|
149
|
+
console.log('User:', userInfo);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Get Account Insights
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const insights = await tiktokProvider.api.getAccountInsights();
|
|
156
|
+
console.log('Insights:', insights);
|
|
157
|
+
// Returns: followerCount, followingCount, likesCount, videoCount, totalViews, averageEngagementRate
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Get Video List
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const videos = await tiktokProvider.api.getVideoList({ maxCount: 20 });
|
|
164
|
+
console.log('Videos:', videos);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Get Video Insights
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const videoInsights = await tiktokProvider.api.getVideoInsights('VIDEO_ID');
|
|
171
|
+
console.log('Video metrics:', videoInsights);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## OAuth Authentication (React Native/Expo)
|
|
175
|
+
|
|
176
|
+
For mobile apps using Expo, import the ExpoAdapter separately:
|
|
48
177
|
|
|
49
178
|
```typescript
|
|
50
|
-
// ExpoAdapter must be imported separately
|
|
51
179
|
import { ExpoAdapter } from '@olastudio/social-media-sdk/adapters/expo';
|
|
52
180
|
import { FacebookProvider } from '@olastudio/social-media-sdk';
|
|
53
181
|
|
|
54
182
|
const oauthAdapter = new ExpoAdapter();
|
|
55
|
-
const facebookProvider = new FacebookProvider({ appId:
|
|
183
|
+
const facebookProvider = new FacebookProvider({ appId: 'YOUR_APP_ID' });
|
|
56
184
|
|
|
57
|
-
//
|
|
185
|
+
// Get OAuth config
|
|
58
186
|
const oauthConfig = facebookProvider.auth.getOAuthConfig(
|
|
59
187
|
['public_profile', 'email', 'pages_manage_posts'],
|
|
60
|
-
|
|
188
|
+
'YOUR_REDIRECT_URI'
|
|
61
189
|
);
|
|
62
190
|
|
|
191
|
+
// Start OAuth flow
|
|
63
192
|
const result = await oauthAdapter.startAuthFlow(oauthConfig);
|
|
64
|
-
|
|
193
|
+
|
|
194
|
+
if (result.type === 'success' && result.accessToken) {
|
|
65
195
|
facebookProvider.setAccessToken(result.accessToken);
|
|
196
|
+
// Now you can use the API
|
|
66
197
|
}
|
|
67
198
|
```
|
|
68
199
|
|
|
69
|
-
##
|
|
70
|
-
|
|
71
|
-
### Facebook
|
|
72
|
-
- Pages management
|
|
73
|
-
- Posts publishing (text, photos, videos)
|
|
74
|
-
- Page insights
|
|
75
|
-
- Fan count
|
|
200
|
+
## Advanced Usage
|
|
76
201
|
|
|
77
|
-
###
|
|
78
|
-
- Account insights
|
|
79
|
-
- Media management
|
|
80
|
-
- Content publishing
|
|
81
|
-
- Stories
|
|
202
|
+
### Custom HTTP Client Configuration
|
|
82
203
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## Deno / Edge Functions
|
|
204
|
+
```typescript
|
|
205
|
+
const provider = new FacebookProvider({
|
|
206
|
+
appId: 'YOUR_APP_ID',
|
|
207
|
+
apiVersion: 'v18.0', // Optional, defaults to v24.0
|
|
208
|
+
});
|
|
209
|
+
```
|
|
90
210
|
|
|
91
|
-
|
|
211
|
+
### Error Handling
|
|
92
212
|
|
|
93
213
|
```typescript
|
|
94
|
-
|
|
95
|
-
import { FacebookProvider, InstagramProvider } from 'npm:@olastudio/social-media-sdk';
|
|
214
|
+
import { APIError, AuthError } from '@olastudio/social-media-sdk';
|
|
96
215
|
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const insights = await facebookProvider.api.getPageInsights(pageId, {
|
|
102
|
-
metric: ['page_impressions'],
|
|
216
|
+
try {
|
|
217
|
+
const insights = await instagramProvider.api.getAccountInsights(accountId, {
|
|
218
|
+
metric: ['reach'],
|
|
103
219
|
period: 'day',
|
|
104
220
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (error instanceof APIError) {
|
|
223
|
+
console.error('API Error:', error.message, error.statusCode);
|
|
224
|
+
} else if (error instanceof AuthError) {
|
|
225
|
+
console.error('Auth Error:', error.message);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## TypeScript Support
|
|
231
|
+
|
|
232
|
+
The SDK is written in TypeScript and includes full type definitions.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import type {
|
|
236
|
+
FacebookPage,
|
|
237
|
+
InstagramAccount,
|
|
238
|
+
InstagramMedia,
|
|
239
|
+
TikTokUserInfo,
|
|
240
|
+
PageInsightsParams,
|
|
241
|
+
AccountInsightsParams,
|
|
242
|
+
} from '@olastudio/social-media-sdk';
|
|
108
243
|
```
|
|
109
244
|
|
|
110
245
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olastudio/social-media-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Modular SDK for managing authentication and APIs of multiple social media platforms",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -62,14 +62,13 @@
|
|
|
62
62
|
"api",
|
|
63
63
|
"expo",
|
|
64
64
|
"react-native",
|
|
65
|
-
"
|
|
66
|
-
"supabase"
|
|
65
|
+
"typescript"
|
|
67
66
|
],
|
|
68
67
|
"author": "Oktopus Dev",
|
|
69
68
|
"license": "MIT",
|
|
70
69
|
"repository": {
|
|
71
70
|
"type": "git",
|
|
72
|
-
"url": "https://github.com/
|
|
71
|
+
"url": "https://github.com/OktopusSolutions/social-media-sdk"
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
74
|
"expo-auth-session": ">=5.0.0",
|