显示所有已注册信标的列表

Display list of all registered beacons

我正在使用信标并希望通过在 python.

中设置 request 在同一网页上显示所有已注册的信标

我很困惑,设置 OAuth2 的范围后,如何发送 requestdiscovery.build() 来获取所有请求的列表。

我是这样设置范围的:

@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)

有人可以帮助我如何通过发出请求来获取所有已注册信标的列表吗?

嗯。我对 Python 没有太多经验,但我很确定 python 有 Google Sign-In 客户,例如 GitHub

有了这个,您可以将登录流程集成到您的应用程序中。

然后,当您调用 Proximity Beacon Admin API 时,您只需设置 HTTP header:

即可进行身份验证
Authorization: Bearer <<OAUTH_BEARER_TOKEN_HERE>>

并且您的通话应该经过正确验证。然后你可以做 python 相当于 http.get() 或 http.post(),添加 HTTP header,你应该能够看到响应。

通过发送这样的请求来完成:

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