Spaces:
Running
Running
File size: 2,428 Bytes
c055c3e c439ea0 c055c3e | 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 | const axios = require('axios');
class PostProxyPoster {
constructor() {
this.apiKey = process.env.POSTPROXY_API_KEY;
this.baseUrl = 'https://api.postproxy.dev/v1';
}
async getProfiles() {
try {
const response = await axios.get(`${this.baseUrl}/profiles`, {
headers: { 'Authorization': `Bearer ${this.apiKey}` }
});
return { success: true, profiles: response.data };
} catch (error) {
console.error('[PostProxy] Get profiles failed:', error.response?.data || error.message);
return { success: false, error: error.message };
}
}
async createPost({ content, mediaUrls = [], profiles = [] }) {
try {
const payload = {
body: content,
media: mediaUrls,
profiles: profiles // Array of profile IDs or slugs like 'linkedin', 'twitter'
};
const response = await axios.post(`${this.baseUrl}/publish`, payload, {
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
}
});
return { success: true, postId: response.data.id, data: response.data };
} catch (error) {
console.error('[PostProxy] Create post failed:', error.response?.data || error.message);
return { success: false, error: error.message };
}
}
async getPostAnalytics(postId) {
try {
const response = await axios.get(`${this.baseUrl}/posts/${postId}/analytics`, {
headers: { 'Authorization': `Bearer ${this.apiKey}` }
});
const d = response.data;
return {
success: true,
analytics: {
likes: d.likes || d.reactions || 0,
comments: d.comments || d.replies || 0,
shares: d.shares || d.reposts || d.retweets || 0,
reach: d.reach || d.impressions || 0,
impressions: d.impressions || 0
}
};
} catch (error) {
console.error('[PostProxy] Get analytics failed:', error.response?.data || error.message);
return { success: false, error: error.message };
}
}
}
module.exports = new PostProxyPoster();
|