Search code examples
pythonflaskgoogle-beacon-platform

Display list of all registered beacons


I am working with beacons and want to display all the registered beacons on a same web page by making the request in python.

I am confused, After setting up the scope of OAuth2, how to send the request or discovery.build() to get list of all the requests.

I am setting up the scope by this:

@portal.route('/oauth2callback')
def oauth2callback():
    flow = client.flow_from_clientsecrets(
        'client_secrets.json',
        scope='https://www.googleapis.com/auth/userlocation.beacon.registry',
        redirect_uri=flask.url_for('portal.oauth2callback', _external=True),
    )
    if 'code' not in flask.request.args:
        auth_uri = flow.step1_get_authorize_url()
        return flask.redirect(auth_uri)
    else:
        auth_code = flask.request.args.get('code')
        credentials = flow.step2_exchange(auth_code)
        flask.session['credentials'] = credentials.to_json()
        return flask.redirect(flask.url_for('portal.index'))



@portal.route('/')
def index():
    if 'credentials' not in flask.session:
        return flask.redirect(flask.url_for('portal.oauth2callback'))
    credentials = client.OAuth2Credentials.from_json(
        flask.session['credentials']
    )
    if credentials.access_token_expired:
        return flask.redirect(flask.url_for('portal.oauth2callback'))
    else:
        http_auth = credentials.authorize(httplib2.Http())
        drive_service = discovery.build('# What should I write')
        # Or, requests.get(What should I write)

Can some one help me how to get list of all registered beacons by making the request.


Solution

  • It get done by sending request like:

    sess = requests.Session()
    req = sess.get('https://proximitybeacon.googleapis.com/v1beta1/beacons', headers={'Authorization': 'Bearer '+credentials.access_token})