Teambition企业内部应用开发指南( 二 )

  • 其中params为查询参数,json为请求体 。根据具体API要求
    • 'params'和'object'中参数用,分隔
    • requests的方法有get/post/del/put根据需要使用
    • 参数后有勾选必填的,必须要有,不然会报错
  • 记得打开相应权限
三、一些辅助脚本Config.pyimport 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 configconfig文件格式[Get_TB_Data]app_id=XXXXXXXXapp_secret=XXXXXXXX
  • 中括号内为Section,条目为option
其他这方面可以自己拓展我个人是写了专门的:数据筛选脚本(根据条件),数据处理脚本(生成json,txt,csv,将国际时间转为北京时间),邮件发送脚本主要是我自己懒得把代码搬上来了,因为逻辑全是连在一起的,不太好动 。如果有需求,可以发送评论,如果方便,我会找机会放上来 。如果追求搜索任务时的自由度的话,可以尝试在历史版本中的TQL查询:https://open.teambition.com/docs/apis/6321c6d4912d20d3b5a4b0b0
四、一些问题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"])

经验总结扩展阅读