Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getAccessToken(callback) {
- var https = require('https');
- var getAccessTokenOptions = {
- host : 'podio.com',
- path : '/oauth/token?grant_type=password&username=[USERNAME]&password=[PASSWORD]&client_id=[CLIENT_ID]&redirect_uri=[REDIRECT_URI]&client_secret=[CLIENT_SECRET]',
- port : 443,
- method : 'POST',
- headers : {
- 'Content-Length' : 0
- }
- };
- var getAccessTokenReq = https.request(getAccessTokenOptions, function(res) {
- res.setEncoding('utf8');
- res.on('data', function(getAccessTokenData) {
- var accessToken = JSON.parse(getAccessTokenData).access_token;
- console.log('Token: ' + accessToken);
- callback(accessToken);
- });
- });
- getAccessTokenReq.on('error', function(e) {
- console.log('problem with request: ' + e.message);
- });
- getAccessTokenReq.end();
- };
- function search(text, accessToken, callback) {
- var query = {
- query : text
- };
- var queryString = JSON.stringify(query);
- var options = {
- host : "api.podio.com",
- path : '/search/',
- port : 443,
- method : "POST",
- headers : {
- 'Authorization' : "OAuth2 " + accessToken,
- 'Content-Length' : Buffer.byteLength(queryString, 'utf8')
- }
- };
- console.log( "Searching for "+ queryString );
- var https = require('https');
- var req = https.request(options, function(result) {
- result.setEncoding('utf8');
- result.on('data', function(data) {
- var result = JSON.parse(data);
- callback(result);
- });
- console.log('STATUS: ' + result.statusCode);
- });
- req.on('error', function(e) {
- console.log('problem with update request: ' + e.message);
- });
- req.write(queryString);
- req.end();
- }
- exports.getAccessToken = getAccessToken;
- exports.search = search;
Add Comment
Please, Sign In to add comment