Skip to content

Instantly share code, notes, and snippets.

@bryanjclark
Created November 9, 2013 23:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjclark/7391350 to your computer and use it in GitHub Desktop.
Save bryanjclark/7391350 to your computer and use it in GitHub Desktop.
I'm trying to build a Python-based push notification process. Eventually, I'll host it on a Mac or on AWS, and send out push notifications through there. Here's my current working copy (I'll update it occasionally) in trying to build that python service.
import time
import json
import requests
from pprint import pprint
# Here's what I want running on the server. For now, I'm running it on my local machine.
# FIRST, WE NEED AN APP TOKEN
appTokenURL = 'https://account.app.net/oauth/access_token'
clientID = 'MY_CLIENT_ID'
clientSecret = 'MY_CLIENT_SECRET'
grantType = 'client_credentials'
appTokenRequestPayload = dict(client_id=clientID, client_secret=clientSecret, grant_type=grantType)
tokenResponseObject = requests.post(appTokenURL,appTokenRequestPayload)
tokenData = json.loads(tokenResponseObject.text)
appAccessToken = tokenData['access_token']
# pprint('Blixt app token is ' + appAccessToken)
# SECOND, WE NEED TO CREATE AN APP STREAM
ADN_HOSTNAME = 'https://alpha-api.app.net'
headerString = '?access_token='+appAccessToken
createStreamEndpoint = ADN_HOSTNAME + '/stream/0/streams'+headerString
objectTypes = ['post','star','user_follow','message']
streamObject = {'endpoint':createStreamEndpoint, 'object_types':objectTypes, 'type':'long_poll', 'key':'io.blixt.blixt-server'}
pprint(json.dumps(streamObject))
blixtStreamResponseObject = requests.post(createStreamEndpoint,json.dumps(streamObject))
blixtStreamData = json.loads(blixtStreamResponseObject.text)
pprint(blixtStreamData)
# Currently, here's what I see in Terminal when I run this:
# '{"endpoint": "https://alpha-api.app.net/stream/0/streams?access_token=MYACCESSTOKENWOULDGOHEREBUTNOTINTHISGIST", "type": "long_poll", "key": "io.blixt.blixt-server", "object_types": ["post", "star", "user_follow", "message"]}'
# {u'meta': {u'code': 400,
# u'error_id': u'ce4c2ca1b0c2436399d1f7309b95c70d',
# u'error_message': u'Bad Request: You must create streams with JSON'}}
# So - what am I doing wrong that I get a bad request?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment