Ejemplo n.º 1
0
#///////////////////////////////////////////////////////////////////////////////////////////////
#
# Set of example calls and examples to the instagram API to setup, review or delete subscriptions.
# 
#
#///////////////////////////////////////////////////////////////////////////////////////////////

cwd = os.getcwd()
cfgs = os.path.join(cwd, 'config/consumeIgram.cfgPrivate')
p = getConfigParameters(cfgs)

# Get the client and secret keys
api = InstagramAPI(client_id=p.client, client_secret=p.secret)

# Create a geographic subscription for San Francisco
api.create_subscription(object='geography', lat=37.7750, lng=-122.4183, radius=5000, aspect='media', callback_url=p.subBaseUrl)

#*** NOTE THAT p.subBaseUrl is in the consumeIgram.cfg config file - change this to whatever your realtime_callback url is ***

# Create a tag based subscription for olympics2012
#api.create_subscription(object='tag', object_id='olympics2012', aspect='media', callback_url=p.subBaseUrl)

# To see a list of your subscriptions, in the browser, hit...
#https://api.instagram.com/v1/subscriptions?client_secret=<yourSecret>&client_id=<yourClient>

# *** There is a way to programmatically hit this too, I just haven't bothered.

# To delete a subscription:
#x = api.delete_subscriptions(id=<get this ID number from looking at the active subscriptions listed - see lines above>)

Ejemplo n.º 2
0
def buildSubscription(event):
    ''' Builds a new subscription based on an GET called event'''

    # Placeholder for doing this by users/algorithm?
    user = '******'

    cwd = os.getcwd()
    cfgs = os.path.join(cwd, 'config/crowded.cfg')
    p = getConfigParameters(cfgs)

    #print "Config Filepath in buildSubscription: ", cfgs

    # The mongo bits
    c, dbh = mdb.getHandle(host=p.dbHost, port=p.dbPort, db=p.db, user=p.dbUser, password=p.dbPassword)
    subsCollHandle = dbh[p.subsCollection]
    evCollHandle   = dbh[p.eventsCollection]
                
    # Check whether we definitely need a new subscription or not    
    checked = checkForExistingSubs(p, subsCollHandle, event)
    
    # If the subscription doesn't already exist, 
    if checked['exists'] == False:
        
        # Get the client and secret keys
        api = InstagramAPI(client_id=p.client, client_secret=p.secret)
    
        # If it's a geo-based subscription
        if event['object'] == 'geography':
            res = api.create_subscription(object='geography', lat=event['lat'], lng=event['lon'], radius=event['radius'],
                                    aspect='media', callback_url=p.subBaseUrl)
            print "Geo Subscription setup: %s" %res
        # A tag-based subscription
        elif event['object'] == 'tag':
            res = api.create_subscription(object='tag', object_id=event['tag'], aspect='media', callback_url=p.subBaseUrl)
            print "Tag Subscription setup: %s" %res
        # Just in case
        else:
            print 'Didnt setup a subscription' 
            res = None
    
        # Update the subscription collection 
        if res and res['meta']['code']==200:
    
            data = res['data']
            subType  = data['object'] 
            objectId = data['object_id'] 
            subId    = data['id']
            aspect   = data['aspect']
            success = updateSubs(subsCollHandle, subType, subId, objectId, aspect, event, user)
            
            # Build the response 
            response = {'success'  : True,
                        'objectId' : objectId,
                        'object'   : subType,
                        'url'      : "%s/%s" %(p.baseUrl, success)}
        
            # Insert a blank document to populate
            _id = buildEventPlaceholder(evCollHandle, subType, event, objectId)
            
        # Something failed in the subscription build...?
        else:
            print '='*40
            print 'Failed here. No event placeholder or subscription updated.'
            print res
            print '='*40
            response = {'success'  : False,
                        'objectId' : checked['objectId'],
                        'object'   : checked['object'],
                        'url'      : "%s/%s" %(p.baseUrl, checked['objectId'])}
    
    # A valid subscription already exists 
    elif checked['exists'] == True:
        response = {'success'  : True,
                    'objectId' : checked['objectId'],
                    'object'   : checked['object'],
                    'url'      : "%s/%s" %(p.baseUrl, checked['objectId'])}

    # Close the connection/handle
    mdb.close(c, dbh)

    return response
Ejemplo n.º 3
0
import bottle
from bottle import route, post, run, request
from instagram import InstagramAPI

CONFIG = {
  'client_id': 'd67c76fb37a541efbb77d0a5a294bcf8',
  'client_secret': 'e6c4c8a1ae344f0aaa261593b116fc8a',
  'redirect_uri': 'http://*****:*****@route('/realtime')
@post('/realtime')
def on_realtime():
    mode = request.GET.get("hub.mode")
    challenge = request.GET.get("hub.challenge")
    verify_token = request.GET.get("hub.verify_token")
    if challenge: 
        return challenge
    else: