首页 > 解决方案 > 如何正确访问 mendeley API?我无法获取文件的 document_id

问题描述

如何访问 mendeley API?( files.document_id)

from mendeley import Mendeley
import requests

# I've changed the authentication details of my script (of course)
client_id = ****
client_secret = "**************"
redirect_uri = "********************"

mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

login_url = auth.get_login_url()

res = requests.post(login_url, allow_redirects=False, data={
    'username': '**********',
    'password': '**********'
})

auth_response = res.headers['Location']

session = auth.authenticate(auth_response)

lib = []
for f in session.files.iter():
    try:
        dic = {}
        dic['filehash'] = f.filehash
        dic['mime_type'] = f.mime_type
        dic['file_name'] = f.file_name
        dic['id'] = f.id
        dic['size'] = f.size
        dic['document_id'] = f.document_id  # I can't access this one.
        lib.append(dic)
    except:
        pass

lib 应该是一个字典列表。根据文档,它应该包含有关“document_id”的信息。(https://dev.mendeley.com/methods/#files)如果我尝试包含 document_id 结果为空。

标签: pythonapimendeley

解决方案


推荐阅读