Skip to content

Instantly share code, notes, and snippets.

@joshtwist
Created December 1, 2012 21:35
Show Gist options
  • Select an option

  • Save joshtwist/4185248 to your computer and use it in GitHub Desktop.

Select an option

Save joshtwist/4185248 to your computer and use it in GitHub Desktop.
Azure Mobile Services script to add name and imageUrl properties on insert
var req = require('request');
function insert(item, user, request) {
item.userId = user.userId;
if (user.userId.indexOf('Twitter:') === 0) {
var twitterId = user.userId.replace('Twitter:', '');
req.get('https://api.twitter.com/1/users/show.json?user_id=' + twitterId,
function(error, result, body) {
item.imageUrl = '';
if (error || result.statusCode != 200) { console.error(error || result); }
var json = JSON.parse(body);
if(json.profile_image_url){
var biggerImg = json.profile_image_url.replace("normal","bigger");
item.imageUrl = biggerImg;
}
item.name = json.name;
request.execute();
});
}
else {
request.execute();
}
}
@molmorg
Copy link
Copy Markdown

molmorg commented Dec 1, 2012

This is for demonstration purposes, needs more robust error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment