0

request我正在使用信标,并希望通过在 python 中制作在同一网页上显示所有已注册的信标。

我很困惑,在设置 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)

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

4

2 回答 2

0

人力资源管理系统。我对 Python 没有太多经验,但我很确定有用于 Python 的 Google 登录客户端,例如GitHub 上的此处。

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

然后,当您调用 Proximity Beacon Admin API 时,您只需设置 HTTP 标头即可进行身份验证:

Authorization: Bearer <<OAUTH_BEARER_TOKEN_HERE>>

并且您的呼叫应该得到正确的身份验证。然后您可以执行类似 http.get() 或 http.post() 的 python 等效操作,添加该 HTTP 标头,您应该能够看到响应。

于 2015-12-09T10:59:12.290 回答
0

它通过发送如下请求来完成:

sess = requests.Session()
req = sess.get('https://proximitybeacon.googleapis.com/v1beta1/beacons', headers={'Authorization': 'Bearer '+credentials.access_token})
于 2015-12-09T12:09:07.177 回答