facebook-nodejs-business-sdk
facebook-nodejs-business-sdk copied to clipboard
9.0 api
Which SDK version are you using?
8.0.3
What's the issue?
the sample code does not run
Steps/Sample code to reproduce the issue
const bizSdk = require('facebook-nodejs-business-sdk');
const ServerEvent = bizSdk.ServerEvent;
const EventRequest = bizSdk.EventRequest;
const CustomData = bizSdk.CustomData;
const access_token = '';
const pixel_id = '';
let current_timestamp = Math.floor(new Date() / 1000);
const customData = (new CustomData())
.setCurrency('usd')
.setValue(123.45);
const serverEvent = (new ServerEvent())
.setEventName('Purchase')
.setEventTime(current_timestamp)
.setCustomData(customData);
const eventsData = [serverEvent];
const eventRequest = (new EventRequest(access_token, pixel_id))
.setEvents(eventsData);
eventRequest.execute().catch(e => {
console.log(e)});
will return error
response: {
error: {
message: '(#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v9.0.',
type: 'OAuthException',
code: 2635,
fbtrace_id: 'ASI0xSDn7DQSMb1ZSzI7CVn'
}
},
Observed Results:
- What happened? This could be a description, log output, etc.
Expected Results:
- What did you expect to happen?
Also experiencing this issue
Hi,
This is happening to me, when could it be fixed?
I have no idea if or when this is going to get fixed, but here's what I did to work around it (for anyone coming to this thread in the future looking for answers).
You can use this library like normal to build the event objects and then just send the data yourself to avoid getting blocked by the SDK_VERSION being set.
Here's some sample code. Go crazy, kids! :+1:
const accessToken = 'FACEBOOK_ACCESS_TOKEN'
const userData = new UserData()
// Set properties on userData
const customData = new CustomData()
// Set properties on customData
const serverEvent = (new ServerEvent())
.setUserData(userData)
.setCustomData(customData)
.setEventName('PageView')
// The library will normalize the event for you; this is what's
// being called inside of the `execute` method we are now avoiding.
const normalizedEvent = serverEvent.normalize()
axios.post(`https://graph.facebook.com/v9.0/${PIXEL_ID}/events`, {
data: [normalizedEvent],
access_token: accessToken,
})
Disclaimer: I have no idea what has actually changed in the Facebook API between v8 and v9. Bear in mind this is more or less short circuiting the versioning system, so the library is still going to normalize the event as if it was building it for v8. It seems to work pretty alright for what little bit of work I'm doing in Facebook, though. :man_shrugging:
I have no idea if or when this is going to get fixed, but here's what I did to work around it (for anyone coming to this thread in the future looking for answers).
You can use this library like normal to build the event objects and then just send the data yourself to avoid getting blocked by the SDK_VERSION being set.
Here's some sample code. Go crazy, kids! 👍
const accessToken = 'FACEBOOK_ACCESS_TOKEN' const userData = new UserData() // Set properties on userData const customData = new CustomData() // Set properties on customData const serverEvent = (new ServerEvent()) .setUserData(userData) .setCustomData(customData) .setEventName('PageView') // The library will normalize the event for you; this is what's // being called inside of the `execute` method we are now avoiding. const normalizedEvent = serverEvent.normalize() axios.post(`https://graph.facebook.com/v9.0/${PIXEL_ID}/events`, { data: [normalizedEvent], access_token: accessToken, })
Disclaimer: I have no idea what has actually changed in the Facebook API between v8 and v9. Bear in mind this is more or less short circuiting the versioning system, so the library is still going to normalize the event as if it was building it for v8. It seems to work pretty alright for what little bit of work I'm doing in Facebook, though. 🤷♂️
Thanks! it works for me, I think using its curl method is much easier than sdk, lol~
Not the best way to do it, but at least it works:
go to
../node_modules/facebook-nodejs-business-sdk/dist/cjs.js
in line 546
change v8.0
to v9.0
works for me, and in addition with https://www.npmjs.com/package/patch-package it should be kind of "stable"
cheerz.
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.