我通过我写的网站在线销售产品。为了管理我的履行流程,当我进行购买时,我希望我的应用在Trello板上自动创建一张卡。
除了几分钟后,即使我以为我创建了永不过期的令牌,我仍可以做的一切都很好。
每次输入订单时,我都无法手动进行身份验证。
这是我编写的用于生成令牌的代码。 (Oauth1)。
步骤1(一次):获取手动授权的资源所有者密钥,资源所有者机密和验证程序。
import requests
from requests_oauthlib import OAuth1Session
oauth = OAuth1Session(CLIENT_KEY,client_secret=CLIENT_SECRET)
fetch_response = oauth.fetch_request_token(REQUEST_TOKEN_URL)
resource_owner_key = fetch_response.get('oauth_token')
resource_owner_secret = fetch_response.get('oauth_token_secret')
print(f'resource_owner_key: {resource_owner_key}')
print(f'resource_owner_secret: {resource_owner_secret}')
auth_url = oauth.authorization_url(AUTHORIZE_TOKEN_URL,scope='read,write',expiration='never') # expiration never
print(auth_url)
# Now manually authenticate in browser using this URL. Record resource owner key,secret and verifier
步骤2(每次):使用资源所有者密钥,资源所有者机密和验证程序来生成令牌。
oauth = OAuth1Session(CLIENT_KEY,client_secret=CLIENT_SECRET,resource_owner_key=RESOURCE_OWNER_KEY,resource_owner_secret=RESOURCE_OWNER_SECRET,verifier=VERIFIER)
oauth_tokens = oauth.fetch_access_token(accESS_TOKEN_URL)
token = oauth_tokens.get('oauth_token')
第3步:在POST请求中使用令牌制作卡片。
这一切在几分钟内都可以正常工作,然后在尝试再次使用它时出现错误:
requests_oauthlib.oauth1_session.TokenRequestDenied: Token request failed with code 500,response was 'token not found'.
我以为令牌是永远存在的?我仍然可以在Trello的帐户下看到其详细信息:
read and write access on all your boards
read and write access on all your teams
Approved: today at 6:30 AM
Never Expires