-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Instagram script to fetch images for a given hash tag #1150
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Description: | ||
# gets photos of hash tag | ||
# | ||
# Dependencies: | ||
# "instagram-node-lib": "*" | ||
# | ||
# Configuration: | ||
# HUBOT_INSTAGRAM_CLIENT_KEY | ||
# HUBOT_INSTAGRAM_ACCESS_KEY | ||
# | ||
# Commands: | ||
# hubot insta tag <tag> <count>- Show recent instagram tags | ||
# by default count is 1 | ||
# | ||
# Author: | ||
# raysrashmi | ||
# | ||
|
||
config = | ||
client_key: process.env.HUBOT_INSTAGRAM_CLIENT_KEY | ||
client_secret: process.env.HUBOT_INSTAGRAM_ACCESS_KEY | ||
|
||
Instagram = require('instagram-node-lib') | ||
Instagram.set('client_id', config.client_key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if config.client_key isn't set in the environment? does Instagram complain? If it does, should consider moving this to the authenticate_user method. Besides that, the name of the method makes it sound like that will happen. |
||
Instagram.set('client_secret', config.client_secret); | ||
module.exports = (robot) -> | ||
robot.respond /(insta tag)( me )?(.*)/i, (msg) -> | ||
count = 1 | ||
authenticate_user() | ||
if msg.match[3] | ||
text = msg.match[3].trim() | ||
text = text.split(" ") | ||
tag = text[0] | ||
count = text[1] if text[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would come back as a string, so you'll need to |
||
else | ||
msg.send 'Please provied tag' | ||
return | ||
Instagram.tags.recent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this API have an option for limiting results? It may be easier to do that, and show all images, rather than doing a while loop below. |
||
name: "#{tag}" | ||
complete: (data) -> | ||
index = 1 | ||
while index <= count | ||
msg.send data[index]['images']['standard_resolution']['url'] | ||
index++ | ||
|
||
authenticate_user = () -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idiomatic coffeescript would be camel case, ie authenticateUser. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and remove the |
||
unless config.client_key | ||
msg.send "Please set the HUBOT_INSTAGRAM_CLIENT_KEY environment variable." | ||
return | ||
unless config.client_secret | ||
msg.send "Please set the HUBOT_TWITTER_ACCESS_TOKEN environment variable." | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it obvious where to get these? Might include any notes or URLs for easily finding these.