使用Python的{Wrike API

时间:2017-10-30 16:49:08

标签: python api

我正在尝试使用带有Python的Wrike API。我无法获得访问令牌。我通过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,因为它需要更多代表。

2 个答案:

答案 0 :(得分: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)

将打印结果粘贴到浏览器中,以检查在归咎于代码之前是否获得了预期的响应。

答案 1 :(得分:1)

我在网上阅读了一段时间后发现了一种更简单的方法。此方法确实需要您在设置wrike应用程序时获得永久令牌。

import requests

url = "https://www.wrike.com/api/v3/tasks"

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

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

print(response.text)
相关问题