如何获得 BlueJeans REST API 的 user_id 或 enterprise_id?
How to obtain a user_id or enterprise_id for the BlueJeans REST API?
我正在尝试在 Python 中使用 BlueJeans REST API,它记录在其 Github 页面 (https://github.com/bluejeans/api-rest-meetings/tree/master/libs/python) and its general API documentation page (https://bluejeans.github.io/api-rest-meetings/site/index.html) 中。
到目前为止,我已经编写了一种使用存储在 Django 设置中的客户端凭据获取令牌的方法:
import json
from urllib.parse import urljoin
import requests
import logging
import BlueJeansMeetingsRestApi
from django.conf import settings
from rest_framework import status
logger = logging.getLogger(__name__)
class ConferenceScheduler(object):
BASE_URL = 'https://api.bluejeans.com'
@staticmethod
def get_token():
# Obtain an access token to initiate a session with BlueJeans
# (We use the Client Grant Type which grants us enterprise-level access)
response = requests.post(
url=urljoin(base=ConferenceScheduler.BASE_URL, url='/oauth2/token'),
json={
'grant_type': 'client_credentials',
'client_id': settings.BLUEJEANS_KEY,
'client_secret': settings.BLUEJEANS_SECRET})
if response.status_code == status.HTTP_200_OK:
return json.loads(response.content).get('access_token')
else:
logger.error(f"A request for a BlueJeans access token returned a non-200 response.\n"
f"Status code: {response.status_code}\n"
f"Reason: {response.reason}")
我在 Django shell 中使用它如下:
In [2]: from lucy_web.lib.conferencing import *
In [3]: BlueJeansMeetingsRestApi.configuration.api_key['access_token'] = ConferenceSch
...: eduler.get_token()
In [4]: api_instance = BlueJeansMeetingsRestApi.ApplicationApi()
In [5]: user_id = settings.BLUEJEANS_USER_ID
In [7]: application = BlueJeansMeetingsRestApi.Application()
在这里,我从 BlueJeans 企业管理控制台的 "BlueJeans Meeting I.D." 字段中获得了 user_id
。但是,如果我尝试创建一个客户端应用程序,我会得到一个 ApiException
来自 401(未授权)HTTP 响应的结果:
In [8]: api_response = api_instance.create_client_application(user_id, application)
---------------------------------------------------------------------------
ApiException Traceback (most recent call last)
<ipython-input-8-1bf90ba9e2a8> in <module>()
----> 1 api_response = api_instance.create_client_application(user_id, application)
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/apis/application_api.py in create_client_application(self, user_id, application, **kwargs)
65 return self.create_client_application_with_http_info(user_id, application, **kwargs)
66 else:
---> 67 (data) = self.create_client_application_with_http_info(user_id, application, **kwargs)
68 return data
69
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/apis/application_api.py in create_client_application_with_http_info(self, user_id, application, **kwargs)
148 _preload_content=params.get('_preload_content', True),
149 _request_timeout=params.get('_request_timeout'),
--> 150 collection_formats=collection_formats)
151
152 def regenerate_client_application_secret(self, user_id, client_id, **kwargs):
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, callback, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
324 body, post_params, files,
325 response_type, auth_settings, callback,
--> 326 _return_http_data_only, collection_formats, _preload_content, _request_timeout)
327 else:
328 thread = threading.Thread(target=self.__call_api,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in __call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, callback, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
151 post_params=post_params, body=body,
152 _preload_content=_preload_content,
--> 153 _request_timeout=_request_timeout)
154
155 self.last_response = response_data
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in request(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)
369 _preload_content=_preload_content,
370 _request_timeout=_request_timeout,
--> 371 body=body)
372 elif method == "PUT":
373 return self.rest_client.PUT(url,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/rest.py in POST(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)
261 _preload_content=_preload_content,
262 _request_timeout=_request_timeout,
--> 263 body=body)
264
265 def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/rest.py in request(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)
217
218 if not 200 <= r.status <= 299:
--> 219 raise ApiException(http_resp=r)
220
221 return r
ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Server': 'BlueJeans Proxy', 'Date': 'Fri, 06 Jul 2018 21:15:54 GMT', 'Cache-Control': 'must-revalidate, no-cache, no-store', 'X-Trace-Token': 'sj1-prod-cobalt-01-158865374', 'Content-Type': 'text/html; charset=ISO-8859-1', 'Content-Length': '280'})
HTTP response body: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 401 </title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing /v1/user/307901319/developer_applications. Reason:
<pre> Unauthorized</pre></p>
<hr />
</body>
</html>
如何获取用户ID或企业ID?从文档来看,似乎所有端点都需要这个,但不清楚如何首先获得它。
原来无法从BlueJeans 管理控制台获取此信息;他们的客户支持通过电子邮件发送给我。
这是我在 Powershell 中的代码,我相信将其重写成 Python 或任何其他语言并不难:
function GetAccessToken()
{
Write-Log-Message "Retrieving access token"
$config = readConfiguration
$postParams = @{grant_type='password';username=$config.username;password=$config.password}
$response = Invoke-WebRequest -Uri https://api.bluejeans.com/oauth2/token?Password -Method POST -Body $postParams | ConvertFrom-Json
$global:access_token = $response.access_token
$global:user_id = $response.scope.user
Write-Log-Message "User $global:user_id"
Write-Log-Message "Access token $global:access_token"
}
您确实可以从客户端凭据 OAuth 调用中获取企业和用户 ID
1) 进行 POST /oauth2/token?Client
调用。您将收到访问令牌和额外字段
{
"access_token": "af9d00...3",
"expires_in": 3600,
"scope": {
"enterprise": 28663,
"partitionName": "z12",
"partition": {
"id": 22,
"name": "z12"
},
"capabilities": []
}
}
从这个API回复你知道企业#:28663
现在,您可以通过匹配的字符串或电子邮件 ID 查找用户:
2) 调用 GET v1/enterprise/28663/users?fields=username,firstName,middleName,lastName,isEnterpriseAdmin,enterpriseJoinDate,email&textSearch=julianne&access_token=6c........03
你将收到返回的数据
{
"count": 1,
"users": [
{
"firstName": "Julianne",
"lastName": "Doe",
"enterpriseJoinDate": 1519967214000,
"middleName": "",
"id": 18314208,
"isEnterpriseAdmin": false,
"uri": "/v1/user/1899208",
"email": "julidoe@mycompany.com",
"username": "Julianne.Doe"
}
]
}
从这个 API,你知道 Julianne 的用户 ID 是:18314208
我正在尝试在 Python 中使用 BlueJeans REST API,它记录在其 Github 页面 (https://github.com/bluejeans/api-rest-meetings/tree/master/libs/python) and its general API documentation page (https://bluejeans.github.io/api-rest-meetings/site/index.html) 中。
到目前为止,我已经编写了一种使用存储在 Django 设置中的客户端凭据获取令牌的方法:
import json
from urllib.parse import urljoin
import requests
import logging
import BlueJeansMeetingsRestApi
from django.conf import settings
from rest_framework import status
logger = logging.getLogger(__name__)
class ConferenceScheduler(object):
BASE_URL = 'https://api.bluejeans.com'
@staticmethod
def get_token():
# Obtain an access token to initiate a session with BlueJeans
# (We use the Client Grant Type which grants us enterprise-level access)
response = requests.post(
url=urljoin(base=ConferenceScheduler.BASE_URL, url='/oauth2/token'),
json={
'grant_type': 'client_credentials',
'client_id': settings.BLUEJEANS_KEY,
'client_secret': settings.BLUEJEANS_SECRET})
if response.status_code == status.HTTP_200_OK:
return json.loads(response.content).get('access_token')
else:
logger.error(f"A request for a BlueJeans access token returned a non-200 response.\n"
f"Status code: {response.status_code}\n"
f"Reason: {response.reason}")
我在 Django shell 中使用它如下:
In [2]: from lucy_web.lib.conferencing import *
In [3]: BlueJeansMeetingsRestApi.configuration.api_key['access_token'] = ConferenceSch
...: eduler.get_token()
In [4]: api_instance = BlueJeansMeetingsRestApi.ApplicationApi()
In [5]: user_id = settings.BLUEJEANS_USER_ID
In [7]: application = BlueJeansMeetingsRestApi.Application()
在这里,我从 BlueJeans 企业管理控制台的 "BlueJeans Meeting I.D." 字段中获得了 user_id
。但是,如果我尝试创建一个客户端应用程序,我会得到一个 ApiException
来自 401(未授权)HTTP 响应的结果:
In [8]: api_response = api_instance.create_client_application(user_id, application)
---------------------------------------------------------------------------
ApiException Traceback (most recent call last)
<ipython-input-8-1bf90ba9e2a8> in <module>()
----> 1 api_response = api_instance.create_client_application(user_id, application)
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/apis/application_api.py in create_client_application(self, user_id, application, **kwargs)
65 return self.create_client_application_with_http_info(user_id, application, **kwargs)
66 else:
---> 67 (data) = self.create_client_application_with_http_info(user_id, application, **kwargs)
68 return data
69
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/apis/application_api.py in create_client_application_with_http_info(self, user_id, application, **kwargs)
148 _preload_content=params.get('_preload_content', True),
149 _request_timeout=params.get('_request_timeout'),
--> 150 collection_formats=collection_formats)
151
152 def regenerate_client_application_secret(self, user_id, client_id, **kwargs):
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, callback, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
324 body, post_params, files,
325 response_type, auth_settings, callback,
--> 326 _return_http_data_only, collection_formats, _preload_content, _request_timeout)
327 else:
328 thread = threading.Thread(target=self.__call_api,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in __call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, callback, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
151 post_params=post_params, body=body,
152 _preload_content=_preload_content,
--> 153 _request_timeout=_request_timeout)
154
155 self.last_response = response_data
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/api_client.py in request(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)
369 _preload_content=_preload_content,
370 _request_timeout=_request_timeout,
--> 371 body=body)
372 elif method == "PUT":
373 return self.rest_client.PUT(url,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/rest.py in POST(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)
261 _preload_content=_preload_content,
262 _request_timeout=_request_timeout,
--> 263 body=body)
264
265 def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
~/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.6/site-packages/BlueJeansMeetingsRestApi/rest.py in request(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)
217
218 if not 200 <= r.status <= 299:
--> 219 raise ApiException(http_resp=r)
220
221 return r
ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Server': 'BlueJeans Proxy', 'Date': 'Fri, 06 Jul 2018 21:15:54 GMT', 'Cache-Control': 'must-revalidate, no-cache, no-store', 'X-Trace-Token': 'sj1-prod-cobalt-01-158865374', 'Content-Type': 'text/html; charset=ISO-8859-1', 'Content-Length': '280'})
HTTP response body: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 401 </title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing /v1/user/307901319/developer_applications. Reason:
<pre> Unauthorized</pre></p>
<hr />
</body>
</html>
如何获取用户ID或企业ID?从文档来看,似乎所有端点都需要这个,但不清楚如何首先获得它。
原来无法从BlueJeans 管理控制台获取此信息;他们的客户支持通过电子邮件发送给我。
这是我在 Powershell 中的代码,我相信将其重写成 Python 或任何其他语言并不难:
function GetAccessToken()
{
Write-Log-Message "Retrieving access token"
$config = readConfiguration
$postParams = @{grant_type='password';username=$config.username;password=$config.password}
$response = Invoke-WebRequest -Uri https://api.bluejeans.com/oauth2/token?Password -Method POST -Body $postParams | ConvertFrom-Json
$global:access_token = $response.access_token
$global:user_id = $response.scope.user
Write-Log-Message "User $global:user_id"
Write-Log-Message "Access token $global:access_token"
}
您确实可以从客户端凭据 OAuth 调用中获取企业和用户 ID
1) 进行 POST /oauth2/token?Client
调用。您将收到访问令牌和额外字段
{
"access_token": "af9d00...3",
"expires_in": 3600,
"scope": {
"enterprise": 28663,
"partitionName": "z12",
"partition": {
"id": 22,
"name": "z12"
},
"capabilities": []
}
}
从这个API回复你知道企业#:28663
现在,您可以通过匹配的字符串或电子邮件 ID 查找用户:
2) 调用 GET v1/enterprise/28663/users?fields=username,firstName,middleName,lastName,isEnterpriseAdmin,enterpriseJoinDate,email&textSearch=julianne&access_token=6c........03
你将收到返回的数据
{
"count": 1,
"users": [
{
"firstName": "Julianne",
"lastName": "Doe",
"enterpriseJoinDate": 1519967214000,
"middleName": "",
"id": 18314208,
"isEnterpriseAdmin": false,
"uri": "/v1/user/1899208",
"email": "julidoe@mycompany.com",
"username": "Julianne.Doe"
}
]
}
从这个 API,你知道 Julianne 的用户 ID 是:18314208