gpt4 book ai didi

python - Mendeley Python SDK 中的身份验证问题

转载 作者:太空狗 更新时间:2023-10-30 00:53:22 26 4
gpt4 key购买 nike

我正在阅读来自 here 的 Mendeley 文档.我正在尝试在我的控制台中获取数据,我正在使用教程中的以下代码

from mendeley import Mendeley

# These values should match the ones supplied when registering your application.
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

现在我不明白在最后一行代码中 auth_response 是从哪里来的?有人知道吗?谢谢

最佳答案

我能够使用以下完全自动化的代码进行试验并使其正常工作。无需用户干预

client_id = 1
client_secret = "XXXXXXXXX"

redirect_uri = "http://localhost:8080/testing"

from mendeley import Mendeley

# These values should match the ones supplied when registering your application.
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

import requests

res = requests.post(login_url, allow_redirects = False, data = {
'username': 'xxxx@gmail.com',
'password': 'xxxxx'
})

auth_response = res.headers['Location']

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

print(session.files.list().items)

最后一行打印[<mendeley.models.files.File object at 0x1115b5400>]这意味着访问权限

关于python - Mendeley Python SDK 中的身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47777288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com