facebook-nodejs-business-sdk
facebook-nodejs-business-sdk copied to clipboard
Error on getStatus of VideoEncodingStatusChecker
Which SDK version are you using?
SDK 7.0
What's the issue?
it is required an await on api.call inside of getStatus method from VideoEncodingStatusChecker
static getStatus(api: FacebookAdsApi, videoId: number) { const result = api.call('GET', [videoId.toString()], {fields: 'status'}); // $FlowFixMe return result['status']; } result is a Promise.
Steps/Sample code to reproduce the issue
const adVideo = new AdVideo( null, { [AdVideo.Fields.filepath]: filepath }, this._account._data.id );
const videoResponse = await adVideo.create();
adVideo[AdVideo.Fields.id] = videoResponse.id;
await adVideo.waitUntilEncodingReady();
Observed Results:
- What happened? This could be a description, log output, etc. UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'video_status' of undefined
Expected Results:
- What did you expect to happen? static getStatus(api: FacebookAdsApi, videoId: number) { const result = await api.call('GET', [videoId.toString()], {fields: 'status'}); // $FlowFixMe return result['status']; }
Same as issue#160
Anyone?
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.
Still requires the community's attention
I am experiencing the same issue
I solved that problem like this.
I added getStatus function in my code
FacebookSDK.prototype.getStatus = function (videoId, params) { return this._api.call("GET", [videoId.toString()], params); };
After that in time upload video I change my code to this
const adVideoInstance = sdk.instance(AdVideo, {
parentId: adAccount.id,
data: { 'filepath': videoData.file } });
const adVideo = await adVideoInstance.create();
const sleepTime = 10; // seconds
const processTimeout = 900; // seconds
let elapsedTime = 0;
const cond = true;
/** Video creating process */
while (cond) {
if (elapsedTime >= processTimeout) {
throw new Error("Video file processing timeout.");
}
await sleep(sleepTime);
elapsedTime += sleepTime;
// Use my own getStatus function
const adVideoLoaded = await sdk.getStatus(adVideo.id, { fields: "status" });
if (adVideoLoaded.status.video_status == "processing") {
console.log("Ad-video status still equal to 'processing'.");
continue;
} else if (adVideoLoaded.status.video_status == "ready") {
return adVideo;
} else {
throw new Error("Video upload error");
}
}
I solved that problem like this.
I added getStatus function in my code
FacebookSDK.prototype.getStatus = function (videoId, params) { return this._api.call("GET", [videoId.toString()], params); };
After that in time upload video I change my code to this
const adVideoInstance = sdk.instance(AdVideo, { parentId: adAccount.id, data: { 'filepath': videoData.file } }); const adVideo = await adVideoInstance.create(); const sleepTime = 10; // seconds const processTimeout = 900; // seconds let elapsedTime = 0; const cond = true; /** Video creating process */ while (cond) { if (elapsedTime >= processTimeout) { throw new Error("Video file processing timeout."); } await sleep(sleepTime); elapsedTime += sleepTime; // Use my own getStatus function const adVideoLoaded = await sdk.getStatus(adVideo.id, { fields: "status" }); if (adVideoLoaded.status.video_status == "processing") { console.log("Ad-video status still equal to 'processing'."); continue; } else if (adVideoLoaded.status.video_status == "ready") { return adVideo; } else { throw new Error("Video upload error"); } }
Hi,
Could you please provide a full example ? I can't manage to find what is sdk
, since instance
does not seem be to working on the facebook-nodejs-business-sdk'
.
Thanks!
Status
Hi @grallc. Here is an example of my code, but you need to change some variables and set your settings.
FacebookBusinessSDK.js
module.exports = require("facebook-nodejs-business-sdk");
FacebookSDK.js
const FacebookBusinessSDK = require("./FacebookBusinessSDK");
const FacebookSDK = function (appId, appSecret, accessToken) {
this._appId = appId;
this._appSecret = appSecret;
this._api = new FacebookBusinessSDK.FacebookAdsApi(accessToken, "en_US");
const defaultApi = FacebookBusinessSDK.FacebookAdsApi.getDefaultApi();
if (!defaultApi) {
FacebookBusinessSDK.FacebookAdsApi.setDefaultApi(this._api);
}
};
FacebookSDK.prototype.instance = function (instanceType, args = {}) {
return new instanceType(args.id || null, args.data || {}, args.parentId || null, this._api);
};
FacebookSDK.prototype.getResource = function (resourceId, params) {
return this._api.call("GET", [resourceId.toString()], params);
};
FacebookBusinessSDK.FacebookSDK = FacebookSDK;
module.exports = FacebookBusinessSDK;
Create-Ad.js
const {AdAccount, AdVideo, FacebookSDK} = require("./FacebookSDK.js");
const sdk = new FacebookSDK(
YOUR_FACEBOOK_APP_ID,
YOUR_FACEBOOK_APP_SECRET,
YOUR_FACEBOOK_ACCESS_TOKEN
);
async function createVideoAd(videoFilePath){
const adVideoInstance = sdk.instance(AdVideo, {
parentId: YOUR_FACEBOOK_AD_ACCOUNT_ID,
data: {
[AdVideo.Fields.filepath]: videoFilePath,
},
});
const adVideo = await adVideoInstance.create();
const sleepTime = 10; // seconds
const processTimeout = 900; // seconds
let elapsedTime = 0;
const cond = true;
/** Video creating process */
while (cond) {
if (elapsedTime >= processTimeout) {
throw new Error("Video file processing timeout.");
}
await sleep(sleepTime);
elapsedTime += sleepTime;
const adVideoLoaded = await sdk.getResource(adVideo.id, { fields: "status" });
if (adVideoLoaded.status.video_status == "processing") {
console.log("Ad-video status still equal to 'processing'.");
continue;
} else if (adVideoLoaded.status.video_status == "ready") {
return adVideo;
} else {
throw new Error("Video upload error");
}
}
throw new Error("Unknown error in time video upload");
}
module.exports = {createVideoAd}
Thanks!