forked from nodejsapps/TypeScript-Node-Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
33 lines (29 loc) · 875 Bytes
/
api.ts
File metadata and controls
33 lines (29 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
import async from "async";
import request from "request";
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
});
});
};