我正在使用信标,并希望通过在python中创建request
来在同一网页上显示所有已注册的信标。
我很困惑,在设置OAuth2的范围后,如何发送request
或discovery.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)
有人可以通过提出请求帮助我获取所有注册信标的列表。
答案 0 :(得分:0)
槽糕。我没有太多使用Python的经验,但我非常确定有用于python的Google登录客户端,例如GitHub上的。
通过这种方式,您可以将登录流程集成到您的应用程序中。
然后,当您调用Proximity Beacon Admin API时,要进行身份验证,您只需设置HTTP标头:
Authorization: Bearer <<OAUTH_BEARER_TOKEN_HERE>>
并且您的电话应该正确验证。然后你可以做类似于http.get()或http.post()的python,添加那个HTTP头,你应该能够看到响应。
答案 1 :(得分:0)
通过发送请求完成:
sess = requests.Session()
req = sess.get('https://proximitybeacon.googleapis.com/v1beta1/beacons', headers={'Authorization': 'Bearer '+credentials.access_token})