使用Python的Wrike API

2024-06-26 10:19:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在Python中使用wrikeapi。我无法获取访问令牌。我对通过API的ouath2很陌生,所以不确定我哪里出错了,任何帮助都是非常感谢的

import json
import os
import requests
import time
import logging
from time import localtime, strftime

wrike_url = "https://wrike.com/"
wrike_user = "username"
wrike_password = "password"
wrike_clientId = "clientid"
wrike_clientSecret = "secret"

logging.basicConfig(level=logging.INFO, format='%(message)s')
logger = logging.getLogger()
logger.addHandler(logging.FileHandler('wrike-log.log', 'a'))
print = logger.info

def wrike_test():
    code = requests.get(wrike_url+"oauth2/authorize?client_id="+wrike_clientId+"&response_type=code")
    print(code.status_code)
    token_url = wrike_url+"oauth2/token/"
    access_token = requests.post(token_url, data = {'client_id' : wrike_clientId,
                                                    'client_secret' : wrike_clientSecret,
                                                    'grant_type' : 'authorization_code',
                                                    'code' : str(code.status_code)
                                                    })
def main():
    wrike_test()
main()

我得到一个404错误。在

无法标记wrike,因为它需要更多的重复


Tags: importclienttokenlogurlsecrettimelogging
2条回答

首先检查服务是否存在,并且您正在生成所需的URL。在

string_to_send = wrike_url+"oauth2/authorize?client_id="+wrike_clientId+"&response_type=code"    
print(string_to_send)
code = requests.get(string_to_send)

将打印的结果粘贴到浏览器中,以检查您是否得到了预期的响应,然后再责怪您的代码。在

在网上读了一段时间后,我找到了一个更简单的方法。这个方法需要你有一个永久性的令牌,这个令牌可以在设置wrike应用程序时获得。在

import requests

# Remember to make sure you are using the correct api version
# The current one is v4
# here are instructions on how to check your version
# https://developers.wrike.com/documentation/api/methods/api-version
api_version = 4
url = f"https://www.wrike.com/api/v{api_version}/tasks"

headers = {
    'authorization': "bearer <your permanent token here>",
    }

response = requests.get(url, headers=headers)

print(response.text)

相关问题 更多 >