Created
October 11, 2016 02:54
-
-
Save shiffman/ee9499ee1b80c532717bf8cd77bb3967 to your computer and use it in GitHub Desktop.
Node + Clarafai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node version of this example: https://github.com/shiffman/A2Z-F16/tree/gh-pages/week3-apis-data/11_clarifai_test | |
// A2Z F16 | |
// Daniel Shiffman | |
// http://shiffman.net/a2z | |
// https://github.com/shiffman/A2Z-F16 | |
var request = require('request'); | |
var clientID = '___'; | |
var clientSecret = '___'; | |
var baseUrl = 'https://api.clarifai.com/v1/'; | |
var accessToken; | |
var data = { | |
'grant_type': 'client_credentials', | |
'client_id': clientID, | |
'client_secret': clientSecret | |
} | |
request.post({url: baseUrl + 'token', form: data}, gotToken); | |
function gotToken(err, response, body) { | |
var result = JSON.parse(body); | |
console.log(result.access_token); | |
var data = { | |
access_token: result.access_token, | |
url: 'http://shiffman.net/images/dan_shiffman.jpeg' | |
} | |
request.post({url: baseUrl + 'tag', form: data}, gotTags); | |
} | |
function gotTags(err, response, body) { | |
if (!err) { | |
var data = JSON.parse(body); | |
console.log(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment