mirror of
https://github.com/microsoft/TypeScript-Node-Starter.git
synced 2025-11-08 16:17:37 +00:00
32 lines
817 B
TypeScript
32 lines
817 B
TypeScript
"use strict";
|
|
|
|
import graph from "fbgraph";
|
|
import { Response, Request, NextFunction } from "express";
|
|
|
|
|
|
/**
|
|
* GET /api
|
|
* List of API examples.
|
|
*/
|
|
export let getApi = (req: Request, res: Response) => {
|
|
res.render("api/index", {
|
|
title: "API Examples"
|
|
});
|
|
};
|
|
|
|
/**
|
|
* GET /api/facebook
|
|
* Facebook API example.
|
|
*/
|
|
export let getFacebook = (req: Request, res: Response, next: NextFunction) => {
|
|
const token = req.user.tokens.find((token: any) => token.kind === "facebook");
|
|
graph.setAccessToken(token.accessToken);
|
|
graph.get(`${req.user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => {
|
|
if (err) { return next(err); }
|
|
res.render("api/facebook", {
|
|
title: "Facebook API",
|
|
profile: results
|
|
});
|
|
});
|
|
};
|