YesCoding

Go to English
search:

Google Social login user birthday

thumbnail_google_birthday

google auth 둜 λ‘œκ·ΈμΈν•œ μœ μ €μ˜ 생년월일을 κ°€μ Έμ˜¬ 수 μžˆλŠ” 방법을 κΈ°λ‘ν•©λ‹ˆλ‹€.

둜그인 ν•œ λ‹€μŒμ— 생년월일을 가져와야 ν•˜λŠ” 상황이닀.

μ§€κΈˆμ€ ꡬ글 λ‘œκ·ΈμΈν•΄μ„œ 받은 accessToken 으둜 κΈ°λ³Έ ν”„λ‘œν•„ μ •λ³΄λŠ” λ°›μ•„μ˜€κ³  μžˆλ‹€.

api: https://www.googleapis.com/oauth2/v2/userinfo

google OAuth docs linkλ₯Ό 보면 email, family_name, gender, hd (host domain), id, link (profile), locale, name, picture, verified_mail 을 보내쀀닀.

μ—¬κΈ°μ—” λ‚΄κ°€ μ›ν•˜λŠ” 생년월일이 μ—†λ‹€.

생년월일을 받을 수 μžˆλŠ” google api λ₯Ό κ²€μƒ‰ν•΄λ³΄λ‹ˆ people google api κ°€ μžˆμ—ˆκ³ , google cloud console 에 λ“€μ–΄κ°€ api λ₯Ό enable μ²˜λ¦¬ν•΄μ£Όκ³  ν˜ΈμΆœν–ˆλ‹€.

google_cloud

google_enable

const URL = 'https://people.googleapis.com/v1/people/me?personFields=birthdays'; // people.googleapis.com const moreInfo = firstValueFrom( this.httpService.get(URL, { headers: { Authorization: `Bearer ${accessToken}`, }, }), ); const test = await moreInfo.then((res) => { console.log(res.data); return res.data; });

people api λ₯Ό μ‚¬μš©ν•˜λ©΄ 생년월일을 받을 수 μžˆλ‹€κ³  ν•΄μ„œ μœ„μ²˜λŸΌ ν˜ΈμΆœν•˜μ˜€μœΌλ‚˜ κ²°κ³Όλ₯Ό μ°μ–΄λ³΄λ‹ˆ 생년월일이 λ‚˜μ˜€μ§€ μ•Šμ•˜λ‹€.

console.log κ²°κ³Ό { resourceName: 'people/113614206436998753985', etag: '%EgQBBy43GgQBAgUH' }

계정 정보에 λ“€μ–΄κ°€ λ³΄λ‹ˆκΉŒ 생년월일 섀정이 μ•ˆ λ˜μ–΄ μžˆμ—ˆλ‹€.

google_birthday

κ·Έλž˜μ„œ 섀정을 ν•˜κ³  λ‹€μ‹œ λ‘œκ·ΈμΈν•΄λ³΄λ‹ˆ μ•„λž˜μ²˜λŸΌ birthdays κ°€ 잘 λ‚˜μ˜΄μ„ ν™•μΈν–ˆλ‹€.

google_birthday_result

birthdays[0].date λ₯Ό 찍어보면

{ year: 1990, month: 4, day: 12 } 둜 λ˜μ–΄ μžˆλ‹€.

ꡬ글 계정에 이미 생년월일 정보가 λ“€μ–΄μžˆκ³  μœ μ €κ°€ μžμ‹ μ˜ 생년월일 곡개 λ²”μœ„λ₯Ό Anyone 으둜 ν•΄λ†“μ•˜λ‹€λ©΄ μš°λ¦¬κ°€ 생년월일을 λ°›μ•„ λ³Ό 수 있음이 ν™•μΈλ˜μ—ˆλ‹€.

Recommend Post
nestjs request dto and response dto
nestjs request dto and response dto
nestjs env variable troubleshooting
nestjs env variable troubleshooting
TypeORM soft delete on cascade
TypeORM soft delete on cascade
tyepORM entityμ—μ„œ λΉ„λ°€λ²ˆν˜Έ hash ν•˜κΈ°
tyepORM entityμ—μ„œ λΉ„λ°€λ²ˆν˜Έ hash ν•˜κΈ°
Β© Copyright 2022, YesCoding