我正在开发一个网络应用程序,允许营销人员发布广告系列并生成潜在客户。我想将Facebook引导广告平台整合到我的网络应用程序中,这样我就可以让营销人员在两个平台上发布广告系列。为此,我需要来自developers.Facebook.com的一些资源或开发人员API。我在那里广泛搜索但没有成功。有人能指出我关于Facebook引导广告的具体开发者指南吗?
答案 0 :(得分:1)
您可以在应用中创建一个Webhook,在创建新潜在客户时触发。
我采取的步骤this post。
只需创建Facebook Webhook可以
的API端点GET
和
POST
然后,当您的Webhook处于活动状态时(这就是GET的用途),您可以在Facebook发布到终端的POST中收到潜在客户信息。
一些代码为您提供上下文(使用Express的Node.js):
'use strict';
var express = require('express');
var controller = require('./facebook.controller');
var router = express.Router();
router.get('/', controller.index);
router.post('/', controller.webhook);
module.exports = router;
GET端点
// Confirm token that was set in the Webhook setup
exports.index = function (req, res) {
console.log(req.query);
var challenge = req.query['hub.challenge'],
verify_token = req.query['hub.verify_token'];
if (verify_token === 'YOUR_TOKEN') {
res.send(challenge);
}
};
POST端点
'use strict';
var _ = require('lodash');
var fb = require('fb');
fb.setAccessToken('acces_token');
var getResponseAPI = require('getresponse-nodejs-api')('API_KEY');
exports.webhook = function(req, res) {
var leadName, leadEmail;
// Lead Info
var fbChanges = req.body.entry[0].changes;
var getLeadFromFacebook = new Promise(function(resolve, reject) {
if (fbChanges !== undefined) {
fbChanges.forEach(function(item, index) {
//You need to retrieve the User info from the changes because Facebook Just gives you UID
var getUserInfoFromGraph = new Promise(
function(resolve, reject) {
var leadId = item.value.leadgen_id;
fb.api(leadId.toString(), function(res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
reject(res.error);
}
resolve(res);
});
}
);
getUserInfoFromGraph.then(function(userInfo) {
//To give you a picture the content of the data
console.log(JSON.stringify(userInfo.field_data));
userInfo.field_data.forEach(function(item) {
if (item.name === 'full_name') {
leadName = item.values[0];
} else if (item.name === 'email') {
leadEmail = item.values[0];
}
});
}).then(function(leadInfo) {
//Work with info here I'm using getResponse :)
getResponseAPI.addContact('CAMPAIGN_ID', leadName, leadEmail, null, 0, {}, function(response) {
if (response.data.error) {
console.log('Error' + response.data.error.message);
}
console.log(JSON.stringify(response));
});
});
});
} else {
res.status(400);
}
});
};