Skip to content

Instantly share code, notes, and snippets.

@shurane shurane/.gitignore
Last active Apr 5, 2019

Embed
What would you like to do?
2019.04.04.pinterest.api
*.log
package-lock.json
node_modules/
secrets.js

To initialize:

npm install

This works:

node github-index.js

Doesn't work yet:

node pinterest-index.js
const request = require('request');
var repl = require("repl");
// https://github.com/request/request
const options = {
url: 'https://api.github.com/repos/request/request',
headers: { 'User-Agent': 'request' }
};
request(options, (err, res, body) => {
if (err) { return console.log(err); }
j = JSON.parse(body);
// https://stackoverflow.com/a/8549188/198348
//var r = repl.start("node> ");
//r.context.body = body;
console.log(j.url);
console.log(j.full_name);
});
console.log("Hello World");
{
"name": "pinterest.api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"client-oauth2": "^4.2.3",
"request": "^2.88.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
const request = require('request');
const clientOAuth2 = require('client-oauth2');
const repl = require("repl");
const secrets = require("./secrets");
/*
// https://www.npmjs.com/package/client-oauth2
const pinterestAuth = new ClientOAuth2({
clientId: '5025677251421710256',
clientSecret: secrets.pinterest.client_secret,
accessTokenUri: 'https://api.pinterest.com/v1/oauth/token',
authorizationUri: 'https://api.pinterest.com/oauth/',
redirectUri: 'https://localhost',
scopes: ['read_public', 'write_public', 'read_relationships', 'write_relationships']
})
const token = pinterestAuth.createToken(secrets.pinterest.access_token);
*/
// https://developers.pinterest.com/docs/api/overview/ (Use Postman to get an access token)
// access token: secrets.pinterest.access_token
// token type: bearer
// scope: ["read_public","write_public","read_private","write_private","read_relationships","write_relationships","read_write_all"]
// some useful content to read:
// https://api.pinterest.com/v1/me/
// https://api.pinterest.com/v1/boards/maryannrizzo/builder-developer-projects/
// https://api.pinterest.com/v1/boards/maryannrizzo/builder-developer-projects/pins/
// https://www.pinterest.com/keifukus
// https://www.pinterest.com/digifireblast
const options = {
url: 'https://api.pinterest.com/v1/boards/maryannrizzo/builder-developer-projects/pins/',
qs: { access_token: secrets.pinterest.access_token },
headers: { 'User-Agent': 'nodejs/requests'}
}
request(options, (err, res, body) => {
if (err) { return console.log(err); }
j = JSON.parse(body);
// https://stackoverflow.com/a/8549188/198348
var r = repl.start("node> ");
r.context.body = body;
r.context.j = j;
console.log(j);
});
const secrets = {
pinterest: {
client_secret: "",
access_token: ""
}
}
module.exports = secrets;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.