json FB-的Instagram-网络挂接 - 淋巴结 - 例如

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json FB-的Instagram-网络挂接 - 淋巴结 - 例如相关的知识,希望对你有一定的参考价值。

// heroku callback url = https://fb-instagram-webhooks.herokuapp.com/facebook
// local callback url = http://rveitch.local.coschedule.ngrok.io/facebook
const dotenv = require('dotenv').load();
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
const xhub = require('express-x-hub');
const _ = require('lodash');
const fbUtilities = require('./utilities/fb-utilities');

const port = Number(process.env.PORT || 3000); // FACEBOOK_APPID

app.set('port', port);
app.listen(app.get('port'));

app.use(xhub({algorithm: 'sha1', secret: process.env.APP_SECRET}));
app.use(bodyParser.json());

const token = process.env.TOKEN || 'token';
const received_updates = [];

app.get('/', function (req, res) {
  console.log(_.pick(req, ['headers', 'body', 'params', 'query']));
  res.send('<pre>' + JSON.stringify(received_updates, null, 2) + '</pre>');
});

app.get(['/facebook', '/instagram'], async (req, res) => {
  if ((req.param('hub.mode') === 'subscribe') && (req.param('hub.verify_token') === token)) {
    res.send(req.param('hub.challenge'));
  }
  res.sendStatus(400);
});

app.post('/facebook', async function (req, res) {
  try {
    console.log('Facebook Request:');
    console.log(JSON.stringify(_.pick(req, ['headers', 'body', 'params', 'query'])));
    console.log('--------------------');

    if (!req.isXHubValid()) {
      console.log('Warning - request header X-Hub-Signature not present or invalid');
      res.sendStatus(401);
      return;
    }

    const webhookUpdate = req.body && req.body.entry.length && req.body.entry[0];
    const userID = webhookUpdate && webhookUpdate.uid;
    if (!userID) {
      console.log('No User ID Found');
      return res.sendStatus(200);
    }

    const userPosts = await fbUtilities.getUserPosts(userID, process.env.FACEBOOK_ACCESS_TOKEN);
    console.log('userPosts', userPosts);

    // Process the Facebook updates here
    received_updates.unshift(req.body);
    res.sendStatus(200);
  } catch (error) {
    console.log('ERROR - /facebook:', error);
    return res.sendStatus(200);
  }
});

app.post('/instagram', function (req, res) {
  console.log('Instagram Request:');
  console.log(JSON.stringify(_.pick(req, ['headers', 'body', 'params', 'query'])));
  console.log('--------------------');

  // Process the Instagram updates here
  received_updates.unshift(req.body);
  res.sendStatus(200);
});

app.listen();
{
  "name": "graph-api-webhooks-samples",
  "version": "0.1.0",
  "description": "Graph API Webhooks Sample",
  "main": "index.js",
  "scripts": {
    "start": "node heroku/index.js"
  },
  "dependencies": {
    "body-parser": "~1.15.0",
    "dotenv": "5.0.1",
    "express": "~4.13.3",
    "express-x-hub": "^1.0.4",
    "lodash": "4.17.10",
    "request": "2.86.0"
  },
  "engines": {
    "node": "8.11.1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/fbsamples/graph-api-webhooks-samples"
  },
  "keywords": [
    "node",
    "heroku",
    "express",
    "graph api"
  ],
  "license": "https://github.com/fbsamples/graph-api-webhooks-samples/blob/master/LICENSE",
  "bugs": "https://github.com/fbsamples/graph-api-webhooks-samples/issues"
}

以上是关于json FB-的Instagram-网络挂接 - 淋巴结 - 例如的主要内容,如果未能解决你的问题,请参考以下文章

从网站(instagram)获取 JSON

在 Instagram 中发布图片

使用 Json.net 的 Instagram API

csharp 最简单基本的网络挂接

sh 网络挂接

FB、WB、IG和TW分别是啥,好像是泰国明星用的啥软件