- 其中
params
为查询参数,json
为请求体 。根据具体API要求
- 'params'和'object'中参数用
,
分隔 - requests的方法有
get/post/del/put
根据需要使用 - 参数后有勾选必填的,必须要有,不然会报错
- 'params'和'object'中参数用
- 记得打开相应权限
import configparserimport os# 读取配置文件def getConfig(filename, section, option):""":param filename 文件名称:param section: 服务:param option: 配置参数:return:返回配置信息"""# 获取当前目录路径proDir = os.path.split(os.path.realpath(__file__))[0]# print(proDir)# 拼接路径获取完整路径configPath = os.path.join(proDir, filename)# print(configPath)# 创建ConfigParser对象conf = configparser.ConfigParser()# 读取文件内容conf.read(configPath)config = conf.get(section, option)return config
config文件格式[Get_TB_Data]app_id=XXXXXXXXapp_secret=XXXXXXXX
- 中括号内为Section,条目为option
四、一些问题Teambition的维护并不好,文档和API中有许多错漏,我已经在10月13向阿里的相关开发者提交了一下报告,不知道何时能修好 。这报告也不全面,是后面才想起来写的 。仅供参考 。
服务器问题(大概)企业获取企业信息(X)
from __future__ import absolute_import, unicode_literalsimport requests, time, jwtclass GetTeamBitionEvents(object):def __init__(self):self.app_id = 'XXXXXXXXXXXXXXXXXXX'self.app_secret = 'XXXXXXXXXXXXXXXXXXX'self.company_url = 'https://www.teambition.com/organization/'self.company_id = 'XXXXXXXXXXXXXXXXXXX'self.callback_url = self.company_url + self.company_idself.user_code = ''self.auth_url = 'https://account.teambition.com/oauth2/authorize?client_id=' + self.app_id + '&redirect_uri=' + self.callback_urldef get_aptoken(self):now_time = int(time.time())expire_time = now_time + 36000# 1 小时后超时token_dict = {'iat': now_time,'_appId': '%s' % self.app_id,'exp': expire_time,}headers = {'typ': 'jwt','alg': 'HS256'# 声明所使用的算法}encoded = jwt.encode(payload=token_dict, key=self.app_secret, headers=headers,algorithm='HS256')# .decode('ascii')return encodeddef post_userapp_visible(self):url = 'https://open.teambition.com/api/org/info'app_token = (self.get_aptoken()).replace("\n", "").replace('\r', '')headers = {"Authorization": 'Bearer %s' % app_token,}params = {"orgId": '%s' % self.company_id}return requests.get(url, params=params, headers=headers)if __name__ == '__main__':tb = GetTeamBitionEvents()result = tb.post_userapp_visible()print(result.json())print(result.json()["result"])
有问题{'code': 403, 'errorMessage': 'Forbidden: authbase.Verify failed: Forbidden: no permission to access resource, appID(6332aa802cd25c2c2880e56b) serviceID(5d4ce50b900cea004806c15a) tenant() resource(organization) action(1)', 'result': None}None
任务更新自由任务标题(X)from __future__ import absolute_import, unicode_literalsimport requests, time, jwtclass GetTeamBitionEvents(object):def __init__(self):self.app_id = 'XXXXXXXXXXXXXXXXXXX'self.app_secret = 'XXXXXXXXXXXXXXXXXXX'self.company_url = 'https://www.teambition.com/organization/'self.company_id = 'XXXXXXXXXXXXXXXXXXX'# 测试用公司self.callback_url = self.company_url + self.company_idself.user_id='XXXXXXXXXXXXXXXXXXX'self.user_code = ''self.auth_url = 'https://account.teambition.com/oauth2/authorize?client_id=' + self.app_id + '&redirect_uri=' + self.callback_urldef get_aptoken(self):now_time = int(time.time())expire_time = now_time + 36000# 1 小时后超时token_dict = {'iat': now_time,'_appId': '%s' % self.app_id,'exp': expire_time,}headers = {'typ': 'jwt','alg': 'HS256'# 声明所使用的算法}encoded = jwt.encode(payload=token_dict, key=self.app_secret, headers=headers,algorithm='HS256')# .decode('ascii')return encodeddef post_create_freetask(self,xoperatorid,content):url = f'https://open.teambition.com/api/organization-task/create'app_token = (self.get_aptoken()).replace("\n", "").replace('\r', '')headers = {'x-operator-id': xoperatorid,'Authorization': 'Bearer %s' % app_token,'X-Tenant-Id': '%s' % self.company_id,'X-Tenant-Type': 'organization',}params={'content':content}return requests.post(url,json=params, headers=headers)if __name__ == '__main__':tb = GetTeamBitionEvents()xoperatorid='63310bc0b2b7b2cf2ca8a3b2'content='all right'result = tb.post_create_freetask(xoperatorid,content)print(result.json())print(result.json()["result"])
经验总结扩展阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 属狗的注册公司用什么名字 霸气吉祥的企业名字
- 冰箱制冷效果不好是什么原因
- IOS12未受信任的企业级开发者怎么解决
- 如何解决未受信任的企业级开发者的问题(如何安装未受信任的企业级开发者)
- ipad未受信任的企业级开发者怎么解决(ipad开发者模式)
- 未受信任的企业级开发者怎么设置(未受信任的企业级开发者有危险吗)
- ipad未受信任的企业级开发者怎么打开(软件在ipad上不受信任)
- ios15未信任企业开发者怎么解决(ios15找不到企业信任)
- iphone未受信任的企业级开发者怎么解决
- 未受信任的企业级开发者怎么解决(未受信任的企业级开发者有危险吗)