如何解决使用带有弹性豆茎的 spotipy oauth 的问题
我在将 Flask 应用程序部署到 Elastic Beanstalk 时尝试使用 spipy 进行用户授权时遇到了这个问题。我收到错误消息,该页面在我的计算机上本地运行时运行正常,但响应时间过长:
@
相比之下,这段代码确实有效(不同的是我没有尝试刷新这段代码中的令牌):
from flask import Flask,request,redirect,render_template
from spotipy.oauth2 import SpotifyOAuth
import spotipy
app = Flask(__name__)
auth = SpotifyOAuth("xxxxxxxxx","xxxxxxxxx","http://mywebsite.com/callback",cache_path=".spotifycache",scope="user-library-read,playlist-modify-public")
sp = spotipy.Spotify(auth_manager=auth)
user = sp.current_user()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/my-link/')
def my_link():
return render_template('result.html')
# Routes
@app.route('/my-link/',methods=['GET','POST'])
def playlist():
token_info = auth.get_cached_token()
if not token_info:
# If there isn't a cached token then you will be redirected to a page where you will be asked to login to spotify
# After that procceed to /callback
auth_url = auth.get_authorize_url()
return redirect(auth_url)
token = token_info['access_token']
# At this point you can now create a Spotifiy instance with
spotipy.client.Spotify(auth=token)
user = sp.current_user()
return render_template('result.html')
@app.route("/callback")
def callback():
url = request.url
code = auth.parse_response_code(url)
token = auth.get_access_token(code)
# Once the get_access_token function is called,a cache will be created making it possible to go through the route "/" without having to login anymore
return redirect("/")
if __name__ == '__main__':
app.run()
提前致谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。