Teambition企業內部應用開發指南( 二 )

config文件格式[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"])有問題
{'code': 403, 'errorMessage': '系統錯誤', 'result': None}創建自由任務(X)同上報錯
查詢自由任務詳情(X)同上
更新自由任務截止時間(X)同上
更新自由任務執行者(?)更新自由任務參與者(?)更新自由任務完成態(?)更新自由任務備注(?)這幾個都沒測了 , 感覺會是一樣的結果
獲取任務關聯信息(X){'code': 403, 'errorMessage': '應用的接口訪問權限受限', 'result': None}創建任務關聯(?)刪除任務關聯(?)更新自由任務優先級(?)這幾個也都沒測了
更新任務自定義字段值(棄用?){'code': 404, 'errorMessage': '訪問的資源不存在', 'result': None}我估計這是被棄用的,因為后面有一條簡介一模一樣的接口

推薦閱讀