I am developing an application to consume the facebook api using the package "facebook-nodejs-business-sdk" in version v9.0.
I'm looking for a method to get interests, but I can't find it.
I looked in the examples available in the package, but I can't find anything that allows me to search the search node.
Using the graph api explorer I can see that the code to make these calls with javascript is as follows:
FB.api( '/search','GET', {"type":"adinterest","q":"Golf","limit":"10000","locale":"pt_BR"}, function(response) { // Insert your code here } );
But the application is using the mentioned package and generally has specific methods for calls.
I'm a beginner in programming so I'm lost.
Can someone help me?
Thanks!
I didn't find any reference to this in the SDK but seems you could call the targeting search api by yourself with the following example:
const bizSdk = require('facebook-nodejs-business-sdk');
const access_token = '<the_token>';
const api = bizSdk.FacebookAdsApi.init(access_token);
const showDebugingInfo = true; // Setting this to true shows more debugging info.
if (showDebugingInfo) {
api.setDebug(true);
}
const params = {
'type' : 'adinterest',
'q' : 'Golf',
'limit' : '10000',
'locale' : 'pt_BR',
};
api.call('GET',['search'], params).then((response) => {
console.log(response)
}).catch(error => {
console.log("something bad happened somewhere", error);
});
This code will output something like:
{
data: [
{
id: '6003631859287',
name: 'Golf',
audience_size: 218921,
path: [Array],
description: null,
disambiguation_category: 'Negócio local',
topic: 'News and entertainment'
},
{
id: '6003510075864',
name: 'Golfe',
audience_size: 310545288,
path: [Array],
description: '',
topic: 'Sports and outdoors'
....
Hope this help
Related
I am having some trouble with the Google APIs and trying to interact with Google Calendar. I'm getting a missing resource 400 error when attempting to insert a new calendar ID.
Below is a snippet of the error JSON (I can't include everything due to some sensitive elements), I don't know what missing resource it's complaining about.
code: 400,
errors: [
{
domain: 'global',
reason: 'required',
message: 'Missing resource.'
}
]
The code that's causing the problem is here (some pieces are omitted):
const { google } = require('googleapis');
const { googlePrivateKey, googleClientEmail, googleProjectNumber } = require('../../config.json');
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
//OMITTED SECTION
const jwtClient = new google.auth.JWT(
googleClientEmail,
'./keyfile.json',
googlePrivateKey,
SCOPES,
);
const calendar = new google.calendar({
version: 'v3',
project: googleProjectNumber,
auth: jwtClient,
});
calendar.calendarList.insert({
id: name,
// 'description': description,
});
Referenced variables are drawn from other surrounding code or from an existing config.json file (not included due to sensitivity of information contained within). The information in config.json is known working (I was able to make a request to retrieve the list of calendars with a 200 response using another piece of code not shown here).
I've looked at as much documentation I can find, but I can't seem to discover any information on what I'm missing/doing wrong.
In your script, how about the following modification?
From:
calendar.calendarList.insert({
id: name,
// 'description': description,
});
To:
const name = "###"; // Please set your calendar ID.
calendar.calendarList.insert(
{
resource: { id: name },
},
(err, res) => {
if (err) {
console.log(err.errors);
return;
}
console.log(res.data);
}
);
Please set your expected calendar ID to name. If this value is not correct, an error like "'Not Found" occurs. Please be careful about this.
Reference:
CalendarList: insert
I am using version 7.2.0 of firebase admin to send fcm push notification, using sendMutlicast method:
async function sendPushRequest({tokens, title, body, customData}) => {
const message = {
notification: {
title,
body,
},
data: customData,
tokens,
}
return firebase.messaging().sendMulticast(message)
}
This is the error I am getting
Error: Exactly one of topic, token or condition is required
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
...
I tried logging the data and here is the object that sendPushRequest function is called with:
{
tokens: [ null, null, null, 'home-test', null, null ], // this one is a recent sample, I've been getting this error for a while now
title: 'some string',
body: 'some other string',
customData: {
title: 'some string',
body: 'some other string',
bigText: 'again another string',
color: '#9f0e27',
smallIcon: 'notificon',
sound: 'default'
}
}
I'm not sure what is causing the error!
I struggled with this problem too, its quite difficult to configure google admin firebase in nodejs. I find out there is a package that can handle this nicely.
https://www.npmjs.com/package/fcm-notification
but it has some little problem . you can not pass it multiple firebase configuration. here is some example :
const fcm = require('fcm-notification');
const fcm_key = require('../config/customer/fcm.json');
const FcM = new fcm(fcm_key);
module.exports.sendToSingleUser = async (message, token) => {
let message_body = {
notification: {
...message
},
token: token
};
FcM.send(message_body, function (err, response) {
if (err) {
return err
} else {
return response
}
})
}
Facing this error too. Figure out that our tokens array contains null or undefiend value. Resolved by remove that from tokens array and everything works fine.
I adapted code from the Google Drive API Quickstart for Node.js found here to try and create a new permission on an existing file in Google Drive.
No matter what I change in the code, I always get the same response saying The permission type field is required even though I've specified it via resource as mentioned in documentation for the npm googleapis client library and other examples I've found.
Is this just not working or am I missing something obvious?
Code to update permission
function updateFilePermissions(auth) {
var drive = google.drive({
version: 'v3',
auth: auth
});
var resourceContents = {
role: 'writer',
type: 'user',
emailAddress: 'user#example.com'
};
drive.permissions.create({
resource: resourceContents,
fileId: aValidFileId,
sendNotificationEmail: false,
fields: 'id',
}, function(err, res) {
if (err) {
// Handle error...
console.error(err);
} else {
console.log('Permission ID: ', res.id);
}
});
}
Response from Google Drive API
code: 400,
errors:
[ { domain: 'global',
reason: 'required',
message: 'The permission type field is required.',
locationType: 'other',
location: 'permission.type' } ]
To anyone that's still looking at the answer, it needs to be formatted like this:
{
fileId: fieldID, // String
resource: {
role: putRoleHere, //String
type: putTypeHere //String
}
Google's APIs are using Axios for the HTTP client so it will be auto-stringified for you when using their methods :)
It seems like the sample code for this API produced by the docs is invalid. By analyzing outgoing requests in the devtools Network and a bit of guessing I found out that the resource fields must be placed in the root level alongside the fileId.
response = await gapi.client.drive.permissions.create({
fileId: "18TnwcUzeBGCHpr7UWW-tKjf2H2RKOKx2V2vaQiHR-TA",
emailMessage: "huj sosi",
sendNotificationEmail: false,
role: 'writer',
type: 'user',
emailAddress: 'user#example.com',
})
Considering that docs don't encourage using a specific version of the library, I suppose there was just a random breaking change in it at some point causing the inconsistency in the docs.
I'm new to NodeJS and Marklogic, I'm following a tutorial on how to save a json document to the database, but I cannot make it work, is my syntax or code correct?
const marklogic = require('marklogic');
const my = require('./my-connection.js');
const db = marklogic.createDatabaseClient(my.connInfo);
const documents = [
{ uri: '/gs/aardvark.json',
content: {
name: 'aardvark',
kind: 'mammal',
desc: 'The aardvark is a medium-sized burrowing, nocturnal mammal.'
}
},
{ uri: '/gs/bluebird.json',
content: {
name: 'bluebird',
kind: 'bird',
desc: 'The bluebird is a medium-sized, mostly insectivorous bird.'
}
}
];
db.documents.write(documents).result(
function(response) {
console.log('Loaded the following documents:');
response.documents.forEach( function(document) {
console.log(' ' + document.uri);
});
},
function(error) {
console.log('error here');
console.log(JSON.stringify(error, null, 2));
}
);
I'm getting 404 error on /gs paths, Is the folder and json file created when I execute this command or do i have to manually create it?
Thank You!
When you say you are getting a "404 error on /gs paths", I assume you're saying you cannot read back the documents you inserted. (It would be nice to see the full error).
If you're not authenticating as a user with admin privileges, you need to make sure the documents are readable. The default permissions (which is what are used here since there's no explicit perms) are rest-reader:read and rest-writer:update. You can read more about these roles here:
http://docs.marklogic.com/guide/node-dev/intro#id_70898
I just joined as associate program in amazon product advertising api. I am able to run query in scratchpad but while in Coding it is giving error. Please give me any suggestion where I am getting wrong. I am using Node.JS for this.
const OperationHelper = require('apac').OperationHelper;
const opHelper = new OperationHelper({
awsId: '',
awsSecret: '',
assocId: 'tarun123-21'
});
opHelper.execute('ItemSearch', {
'SearchIndex': 'Books',
'Keywords': 'harry potter',
'ResponseGroup': 'ItemAttributes,Offers',
'Service' : 'AWSECommerceService'
}).then((response) => {
console.log("Results object: ", response.result);
console.log("Raw response body: ", response.responseBody);
}).catch((err) => {
console.error("Something went wrong! ", err);
});
It is giving the following error :
Results object: { ItemSearchErrorResponse:
{ '$': { xmlns: 'http://ecs.amazonaws.com/doc/2013-08-01/' },
Error:
{ Code: 'AWS.InvalidAssociate',
Message: 'Your AKIAI7SZEKEZNMFWGJDQ is not registered as an Amazon Assoc
iate. Please register as an associate at https://affiliate-program.amazon.com/gp
/associates/join/landing/main.html.' },
RequestId: 'e860887e-4bf7-4076-bfa9-6d2212324ba4' } }
Raw response body: <?xml version="1.0"?>
<ItemSearchErrorResponse xmlns="http://ecs.amazonaws.com/doc/2013-08-01/"><Error
><Code>AWS.InvalidAssociate</Code><Message>Your AKIAI7SZEKEZNMFWGJDQ is not regi
stered as an Amazon Associate. Please register as an associate at https://affili
ate-program.amazon.com/gp/associates/join/landing/main.html.</Message></Error><R
equestId>e860887e-4bf7-4076-bfa9-6d2212324ba4</RequestId></ItemSearchErrorRespon
se>
As the error suggest you will need Amazon Associate account to access the API. The credentials that you are using seems invalid. You can test your credentials here Amazon Scratch pad