forked from ayrshare/social-media-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
228 lines (198 loc) · 5.62 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
const SocialPost = require("./index.js");
/**
* Add your API Key to a .json file, Profile Key (Business Plan), and Domain (Business Plan)
* {
* "API_KEY": "your api key",
* "PROFIL_KEY": "user profile key",
* "DOMAIN": "Business Plan domain"
* }
*/
const { API_KEY, PROFILE_KEY, DOMAIN } = require("./config.json");
const social = new SocialPost(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 */
const testPost = async () => {
const post = await social.post({
randomPost: true,
// platforms: ["twitter", "facebook", "linkedin", "instagram"],
platforms: ["twitter"],
randomMediaUrl: true,
shortenLinks: true,
requiresApproval: true,
});
console.log("testPost: ", post);
return post.id;
};
/** 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 run = async () => {
const id = await testPost();
// 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"]);
*/
/** Business Plan */
/*
testCreateProfile();
testCreateandDelete();
testGenerateJWT();
testUnlinkSocial(PROFILE_KEY, "twitter");
testGetBrandByUser(["instagram"], "@ayrshare");
testUpdateProfile(PROFILE_KEY);
*/
run();