-
Notifications
You must be signed in to change notification settings - Fork 28
/
test.js
431 lines (374 loc) · 11 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
// npx rollup index.js --file index.cjs --format cjs
import SocialMediaAPI from "./index.js";
/**
* Add your API Key to a config.js file, Profile Key (Business Plan), and Domain (Business Plan)
* {
* "API_KEY": "your api key",
* "PROFIL_KEY": "user profile key",
* "DOMAIN": "Business Plan domain"
* }
*/
import config from "./config.js";
const { API_KEY, PROFILE_KEY, DOMAIN } = config;
const social = new SocialMediaAPI(API_KEY);
/** Test history */
const testHistory = async (platform, id) => {
const history = await social.history(
platform ? { platform } : id ? { id } : null
);
console.log("testHistory:", history);
};
/** Test get details on the current user */
const testUser = async () => {
const user = await social.user();
console.log("testUser:", user);
};
/** Test Add a feed */
const testFeed = async () => {
const feedAdd = await social.feedAdd({
type: "substack",
url: "https://bankless.substack.com/"
});
console.log("testFeed:", feedAdd);
};
/** Test Auto Schedule */
const testAutoSchedule = async () => {
const setAutoSchedule = await social.setAutoSchedule({
schedule: ["13:05Z", "20:14Z"],
title: "test"
});
console.log("testAutoSchedule:", setAutoSchedule);
};
/** Test delete */
const testDelete = async (id) => {
const deletePost = await social.delete({ id });
console.log("testDelete:", deletePost);
};
/** Test post
* Uncomment the platforms you want to post to and/or include the random video.
*/
const testPost = async () => {
const post = await social.post({
randomPost: true,
// platforms: ["twitter", "facebook", "linkedin", "instagram", "tiktok"],
platforms: ["twitter"],
randomMediaUrl: true,
// isLandscapeVideo: true,
shortenLinks: true,
// requiresApproval: true
});
console.log("testPost: ", post);
return post.id;
};
const testGetPost = async (id) => {
const post = await social.getPost({ id });
console.log("testGetPost: ", post);
};
const testRetryPost = async (id) => {
const post = await social.retryPost({ id });
console.log("testRetryPost: ", post);
};
/** Test Post Update */
const testPostUpdate = async (id) => {
const post = await social.updatePost({
id,
approved: true
});
console.log("test post update: ", post);
return post.id;
};
/** Test Instagram post */
const testInstagramPost = async () => {
const postInstagram = await social.post({
randomPost: true,
platforms: ["instagram"],
media_urls: ["https://images.ayrshare.com/imgs/GhostBusters.jpg"],
tagged: ["@ayrshare"],
shorten_links: true
});
console.log("testInstagramPost:", postInstagram);
};
/** Test Upload - Video required*/
const testVideoPost = async () => {
const datauri = require("datauri");
const content = await datauri("./test-video.mp4");
const upload = await social.upload({
file: content,
fileName: "Test.mp4",
description: "A great test"
});
console.log("testVideoPost:", upload);
};
const testAnalytics = async (id) => {
const analytics = await social.analyticsPost({
id,
// platforms: ["facebook", "instagram", "twitter", "linkedin"],
platforms: ["facebook"]
});
return console.log("testAnalytics:", analytics);
};
const testAnalyticsSocial = async (platforms) => {
const analytics = await social.analyticsSocial({
platforms
});
return console.log("testAnalyticsSocial:", analytics);
};
const testGetComments = async (id) => {
const analytics = await social.getComments({
id
});
return console.log("testGetComments:", analytics);
};
const testListWebhooks = async () => {
const listWebhooks = await social.listWebhooks();
console.log("testListWebhooks:", listWebhooks);
};
const testPostComment = async (id) => {
const analytics = await social.postComment({
id,
platforms: ["facebook", "instagram"],
comment: "My thoughts exactly"
});
return console.log("testPostComment:", analytics);
};
/** Business Plan Membership - required ---------------- */
const testCreateProfile = async () => {
const createProfile = await social.createProfile({
title: "Best Profile Title Ever"
});
console.log(createProfile);
return createProfile.profileKey;
};
const testDeleteProfile = async (profileKey) => {
const deleteProfile = await social.deleteProfile({
profileKey: profileKey
});
console.log("testDeleteProfile:", deleteProfile);
};
const testCreateandDelete = async () => {
const profileKey = await testCreateProfile();
return testDeleteProfile(profileKey);
};
const testGenerateJWT = async () => {
const fs = require("fs");
const privateKey = fs.readFileSync(`./private.key`, "utf8");
const jwt = await social.generateJWT({
domain: DOMAIN,
privateKey,
profileKey: PROFILE_KEY
});
return console.log("testGenerateJWT", jwt);
};
const testUpdateProfile = async (profileKey) => {
const updateProfile = await social.updateProfile({
profileKey,
title: "A Nice Title"
});
console.log("UpdateProfile:", updateProfile);
};
const testUnlinkSocial = async (profileKey, platform) => {
const unlinkSocial = await social.unlinkSocial({ profileKey, platform });
console.log("testUnlinkSocial:", unlinkSocial);
};
const testGetBrandByUser = async (platforms, username) => {
const getBrandByUser = await social.getBrandByUser({
platforms,
instagramUser: username
});
console.log("testGetBrandByUser:", getBrandByUser);
};
const testVerifyMediaExists = async (mediaUrl) => {
const verifyMediaExists = await social.verifyMediaExists({
mediaUrl
});
console.log("testVerifyMediaExists:", verifyMediaExists);
};
const testMediaMeta = async (url) => {
const mediaMeta = await social.mediaMeta({
url
});
console.log("testMediaMeta:", mediaMeta);
};
const testMediaUploadUrl = async (fileName, contentType) => {
const mediaMeta = await social.mediaUploadUrl({
fileName,
contentType
});
console.log("testMediaUploadUrl:", mediaMeta);
};
const testResizeImage = async (imageUrl, platform) => {
const resizeImage = await social.resizeImage({
imageUrl,
platform
});
console.log("testResizeImage:", resizeImage);
};
const testAutoHashtags = async (post) => {
const autoHashtags = await social.autoHashtags({
post
});
console.log("testAutoHashtags:", autoHashtags);
};
const testRecommendHashtags = async (keyword) => {
const recommendHashtags = await social.recommendHashtags({
keyword
});
console.log("testRecommendHashtags:", recommendHashtags);
};
const testCheckBannedHashtags = async (hashtag) => {
const checkBannedHashtags = await social.checkBannedHashtags({
hashtag
});
console.log("testCheckBannedHashtags:", checkBannedHashtags);
};
const testReviews = async (platform) => {
const reviews = await social.reviews({ platform });
console.log("testReviews:", reviews);
};
const testReview = async (id, platform) => {
const review = await social.review({
id,
platform
});
console.log("testReview:", review);
};
const testReplyReview = async (reviewId, platform, reply) => {
const replyReview = await social.replyReview({
reviewId,
platform,
reply
});
console.log("testReplyReview:", replyReview);
};
const testDeleteReplyReview = async (reviewId, platform) => {
const deleteReplyReview = await social.deleteReplyReview({
reviewId,
platform
});
console.log("testDeleteReplyReview:", deleteReplyReview);
};
const testDeleteComments = async (id) => {
const deleteComment = await social.deleteComments({
id
});
console.log("testDeleteComment:", deleteComment);
};
const testReplyComment = async (commentId, platforms, comment) => {
const replyComment = await social.replyComment({
commentId,
platforms,
comment
});
console.log("testReplyComment:", replyComment);
};
/** ------------------------------------------------ */
/** Max Pack - required ---------------- */
const testGeneratePost = async (text) => {
const generatePost = await social.generatePost({
text
});
console.log("testGeneratePost:", generatePost);
};
const testGenerateRewrite = async (post) => {
const generateRewrite = await social.generateRewrite({
post
});
console.log("testGenerateRewrite:", generateRewrite);
};
const testGenerateTranscription = async (videoUrl) => {
const generateTranscription = await social.generateTranscription({
videoUrl
});
console.log("testGenerateTranscription:", generateTranscription);
};
const testGenerateTranslation = async (text, lang) => {
const generateTranslation = await social.generateTranslation({
text,
lang
});
console.log("testGenerateTranslation:", generateTranslation);
};
const testGenerateAltText = async (url) => {
const generateAltText = await social.generateAltText({
url
});
console.log("testGenerateAltText:", generateAltText);
};
const testShortLink = async (url) => {
const shortLink = await social.shortLink({
url
});
console.log("testShortLink:", shortLink);
};
const testShortLinkAnalytics = async (id) => {
const shortLinkAnalytics = await social.shortLinkAnalytics({
id
});
console.log("testShortLinkAnalytics:", shortLinkAnalytics);
};
/** ------------------------------------------------ */
const run = async () => {
const id = await testPost();
// await testGetPost(id);
// await testRetryPost(id);
// const update = await testPostUpdate(id);
// await testPostComment(id);
// await testAnalytics("lZDx0mCKwpgCHGp9gLy5");
// await testGetComments(id);
// testDelete(id);
};
/*
testHistory();
testUser();
testAutoSchedule();
testFeed();
testPost();
testInstagramPost();
testVideoPost();
testAnalytics(id);
testComments();
testListWebhooks();
testAnalyticsSocial(["facebook"]);
testMediaMeta("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg");
testDeleteComment("XOVUGutufIy5UZFb01e0");
testReplyComment(
"Nsa2SWqt32BuY4ooeh7Au",
["instagram"],
"Thank you for the comment!"
);
*/
/** Business Plan */
/*
testCreateProfile();
testCreateandDelete();
testGenerateJWT();
testUnlinkSocial(PROFILE_KEY, "twitter");
testGetBrandByUser(["instagram"], "@ayrshare");
testUpdateProfile(PROFILE_KEY);
testMediaUploadUrl("tree.jpg", "jpeg");
testVerifyMediaExists(
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"
);
testResizeImage(
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg",
"facebook"
);
testAutoHashtags("This is a test post");
testRecommendHashtags("post");
testCheckBannedHashtags("instagram");
testReviews("facebook");
testReview("10114455408676943", "facebook");
testReplyReview("10114455408676943", "facebook", "Thank you for the review!");
testDeleteReview("10114455408676943", "facebook");
*/
/* Max Pack */
/*
testGeneratePost("This is a test post");
testGenerateRewrite("This is a test post");
testGenerateTranscription("https://img.ayrshare.com/random/landscape5.mp4");
testGenerateTranslation("This is a test post", "fr");
testGenerateAltText("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg");
testShortLink("https://www.ayrshare.com/");
testShortLinkAnalytics("qR--d8");
*/
run();