Closed dguk25 closed 2 years ago
some problem for me. what python
version are you using to make it work?
What is the required content of mendeley_token
. it looks a bit weird to me.
I am not too much into OAuth
, but I thought it would also like to use the auth_token
so why are you doing all this de- and encoding?
Anyway, thanks for the script and your efforts!
I'm using Python 3.8.9 but it has worked with other 3.* versions before.
and pip3 list
shows these versions.
mendeley 0.3.2
mendeley-cli 0.3.0
python-dotenv 0.19.0
thanks for your the info!
maybe the problem is somewhere when getting the auth_token
.
I am describing the steps which I made in getting there, following your comments in the code:
.mendeley_config
file, which are
MENDELEY_CLIENT_SECRET=*****************
MENDELEY_CLIENT_ID=12628
MENDELEY_REDIRECT_URI=http://localhost:8888/
https://api.mendeley.com/oauth/authorize?client_id=12628&redirect_uri=http:%2F%2Flocalhost:8888%2F&response_type=code&scope=all
and was redirected to my localhost
+ the required authorization_code
from mendeley:
http://localhost:8888/?code=*************************&reset
curl
:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --user "12628:*MENDELEY_CLIENT_SECRET*" -d "grant_type=authorization_code&code=*authorization_code*&redirect_uri=http:%2F%2Flocalhost:8888%2F" https://api.mendeley.com/oauth/token
token
also in my .mendeley_config
as MENDELEY_OAUTH2_TOKEN_BASE64
and added a =
add the end, see #1 I checked the return of the following call, within the json.loads()
call first:
base64.b64decode(mendeley_token_b64.encode()).decode()
and received something like
'1,1651654805765,20855841,12628,all,,,bbba50**************************************1-b7bf***************************1110,iF0R*******************j5t0'
So everything looks pretty similar to your README
file despite the mendeley-cli
which I cannot get running due to IT restirctions at my workplace.
Do you get something similar when running the last code snippet?
Many thanks in advance
Ok, so I decoded the token I get with mendeley-cli
and here's what it looks like:
{"access_token": "***", "token_type": "bearer", "expires_in": 3600, "refresh_token": "***", "msso": null, "scope": ["all"], "expires_at": 1651617581.135136}
So instead of just entering the access token you got in step 4, encode the entire json response (which looks like above I hope) and use that for MENDELEY_OAUTH2_TOKEN_BASE64. I did the encoding here (https://www.base64encode.org/) and it worked! Hope that'll work for you as well.
if it works, I'll link this issue in the README for users who cannot use mendeley-cli
okay, now I got it:
I took the whole response from the curl
or mendeley-cli
call and did a base64.b64decode()
with that before saving it to the .mendeley.config
file.
However, I also needed to change the script at https://github.com/anilkyelam/mendeley-rMsync/blob/4b17eae4cf3a21b70aa9c4ea1547704c3807e3b6/sync.py#L122 to
mendeley_token = json.loads(base64.b64decode(mendeley_token_b64.encode()).decode().rstrip("="))
as the decoded string was automatically padded with =
which json.loads
does not like.
thanks for your help
could you plese delete the duplicate?
After running sync I keep getting this error...
Have tried generating secret key and access token a number of times. Seems to be the way sync is handling the access token. What am I doing wrong?
Thanks!