@meltwater/conversations-api-services 1.4.0 → 1.4.1
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.
|
@@ -21,6 +21,7 @@ var _externalIdHelpers = require("../../lib/externalId.helpers.js");
|
|
|
21
21
|
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
22
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
23
|
const FACEBOOK_URL = 'https://graph.facebook.com';
|
|
24
|
+
const versionLock = 'v25.0';
|
|
24
25
|
async function shareCount(token, externalId, logger) {
|
|
25
26
|
const response = await getApi(`${FACEBOOK_URL}/${(0, _externalIdHelpers.removePrefix)(externalId)}/?fields=shares`, token, undefined, {}, logger);
|
|
26
27
|
return response.body.shares && response.body.shares.count;
|
|
@@ -245,8 +246,9 @@ async function getProfile(token, authorId, fields, logger) {
|
|
|
245
246
|
}
|
|
246
247
|
async function ban(token, sourceId, authorId, logger) {
|
|
247
248
|
(0, _loggerHelpers.loggerDebug)(logger, `Starting to call facebook ban api for externalAuthorId ${authorId} ${sourceId}`);
|
|
248
|
-
const response = await postApi(`${FACEBOOK_URL}/${(0, _externalIdHelpers.removePrefix)(sourceId)}/blocked`,
|
|
249
|
-
|
|
249
|
+
const response = await postApi(`${FACEBOOK_URL}/${versionLock}/${(0, _externalIdHelpers.removePrefix)(sourceId)}/blocked`, undefined, {
|
|
250
|
+
user: `${(0, _externalIdHelpers.removePrefix)(authorId)}`,
|
|
251
|
+
access_token: token
|
|
250
252
|
}, logger);
|
|
251
253
|
(0, _loggerHelpers.loggerInfo)(logger, `Native Facebook API Hide Response for externalAuthorId ${authorId}`, {
|
|
252
254
|
responseBody: JSON.stringify(response.body)
|
|
@@ -341,9 +343,10 @@ async function postApi(apiUrl, accessToken, payload, logger) {
|
|
|
341
343
|
let isMultipart = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
342
344
|
let response = {};
|
|
343
345
|
try {
|
|
344
|
-
const
|
|
346
|
+
const query = accessToken ? {
|
|
345
347
|
access_token: accessToken
|
|
346
|
-
}
|
|
348
|
+
} : payload;
|
|
349
|
+
const request = _superagent.default.post(apiUrl).set('Accept', 'application/json').query(query);
|
|
347
350
|
if (isMultipart) {
|
|
348
351
|
request.type('form');
|
|
349
352
|
for (const key in payload) {
|
|
@@ -2,6 +2,7 @@ import superagent from 'superagent';
|
|
|
2
2
|
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
3
|
import { loggerDebug, loggerInfo, MeltwaterAttributes } from '../../lib/logger.helpers.js';
|
|
4
4
|
const FACEBOOK_URL = 'https://graph.facebook.com';
|
|
5
|
+
const versionLock = 'v25.0';
|
|
5
6
|
export async function shareCount(token, externalId, logger) {
|
|
6
7
|
const response = await getApi(`${FACEBOOK_URL}/${removePrefix(externalId)}/?fields=shares`, token, undefined, {}, logger);
|
|
7
8
|
return response.body.shares && response.body.shares.count;
|
|
@@ -226,8 +227,9 @@ export async function getProfile(token, authorId, fields, logger) {
|
|
|
226
227
|
}
|
|
227
228
|
export async function ban(token, sourceId, authorId, logger) {
|
|
228
229
|
loggerDebug(logger, `Starting to call facebook ban api for externalAuthorId ${authorId} ${sourceId}`);
|
|
229
|
-
const response = await postApi(`${FACEBOOK_URL}/${removePrefix(sourceId)}/blocked`,
|
|
230
|
-
|
|
230
|
+
const response = await postApi(`${FACEBOOK_URL}/${versionLock}/${removePrefix(sourceId)}/blocked`, undefined, {
|
|
231
|
+
user: `${removePrefix(authorId)}`,
|
|
232
|
+
access_token: token
|
|
231
233
|
}, logger);
|
|
232
234
|
loggerInfo(logger, `Native Facebook API Hide Response for externalAuthorId ${authorId}`, {
|
|
233
235
|
responseBody: JSON.stringify(response.body)
|
|
@@ -322,9 +324,10 @@ async function postApi(apiUrl, accessToken, payload, logger) {
|
|
|
322
324
|
let isMultipart = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
323
325
|
let response = {};
|
|
324
326
|
try {
|
|
325
|
-
const
|
|
327
|
+
const query = accessToken ? {
|
|
326
328
|
access_token: accessToken
|
|
327
|
-
}
|
|
329
|
+
} : payload;
|
|
330
|
+
const request = superagent.post(apiUrl).set('Accept', 'application/json').query(query);
|
|
328
331
|
if (isMultipart) {
|
|
329
332
|
request.type('form');
|
|
330
333
|
for (const key in payload) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Repository to contain all conversations api services shared across our services",
|
|
5
5
|
"main": "dist/cjs/data-access/index.js",
|
|
6
6
|
"module": "dist/esm/data-access/index.js",
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '../../lib/logger.helpers.js';
|
|
8
8
|
|
|
9
9
|
const FACEBOOK_URL = 'https://graph.facebook.com';
|
|
10
|
+
const versionLock = 'v25.0';
|
|
10
11
|
|
|
11
12
|
export async function shareCount(token, externalId, logger) {
|
|
12
13
|
const response = await getApi(
|
|
@@ -332,9 +333,12 @@ export async function ban(token, sourceId, authorId, logger) {
|
|
|
332
333
|
);
|
|
333
334
|
|
|
334
335
|
const response = await postApi(
|
|
335
|
-
`${FACEBOOK_URL}/${removePrefix(sourceId)}/blocked`,
|
|
336
|
-
|
|
337
|
-
{
|
|
336
|
+
`${FACEBOOK_URL}/${versionLock}/${removePrefix(sourceId)}/blocked`,
|
|
337
|
+
undefined,
|
|
338
|
+
{
|
|
339
|
+
user: `${removePrefix(authorId)}`,
|
|
340
|
+
access_token: token
|
|
341
|
+
},
|
|
338
342
|
logger
|
|
339
343
|
);
|
|
340
344
|
|
|
@@ -489,10 +493,12 @@ async function postApi(
|
|
|
489
493
|
) {
|
|
490
494
|
let response = {};
|
|
491
495
|
try {
|
|
496
|
+
const query = accessToken ? { access_token: accessToken } : payload;
|
|
497
|
+
|
|
492
498
|
const request = superagent
|
|
493
499
|
.post(apiUrl)
|
|
494
500
|
.set('Accept', 'application/json')
|
|
495
|
-
.query(
|
|
501
|
+
.query(query);
|
|
496
502
|
|
|
497
503
|
if (isMultipart) {
|
|
498
504
|
request.type('form');
|