Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

javascript - How to get code from Facebook Authorization request?

I need to pass the Facebook Authorization code as a value to my back-end during a sign in. I've figured out that I can generate a code by requesting it via https://www.facebook.com/v8.0/dialog/oauth?client_id=6**********&redirect_uri=http://localhost:3000/*****/***

Which returns a url: http://localhost:3000/****/******?code=AQDrfYDvQdrWxd*************nI6QfJrZqDBW-diVXr0vSWr7eDNyJ6axCPx_gYubndupibMHiI0gVnPT8I4cfun240_01DzweTsq7F7Hk7d1Vnrfl4F4YREjOAt8LZmk83EHKexsLQrs2QbbIki6u51m90tGbo_WzxUg5Q#_=_

How do I get the code from this request by using Javascript or Axios?

question from:https://stackoverflow.com/questions/65928347/how-to-get-code-from-facebook-authorization-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If it is the code you want to extract from the url you can do it like this.

const returnUrl = 'http://localhost:3000/****/******?code=AQDrfYDvQdrWxd*************nI6QfJrZqDBW-diVXr0vSWr7eDNyJ6axCPx_gYubndupibMHiI0gVnPT8I4cfun240_01DzweTsq7F7Hk7d1Vnrfl4F4YREjOAt8LZmk83EHKexsLQrs2QbbIki6u51m90tGbo_WzxUg5Q#_=_';
const url = new URL(returnUrl);
const code = url.searchParams.get('code');
console.log(code);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...