Get Ready to Use the People API에 설명 된 단계를 따르십시오. Java, Python, PHP, .NET으로 작성된 예제를 찾을 수 있습니다.
의 1 단계 완료 및 2. 다음은 권한 부여 요청을 만들 수있는 크리스탈 코드입니다 가정 해 봅시다 :
require "oauth2"
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
scope = "profile"
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
client = OAuth2::Client.new(
"accounts.google.com",
client_id,
client_secret,
authorize_uri: "/o/oauth2/v2/auth",
redirect_uri: redirect_uri
)
authorize_uri = client.get_authorize_uri(scope)
authorize_uri #=> https://accounts.google.com/o/oauth2/v2/auth?client_id=CLIENT_ID&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts.readonly
열기, 브라우저에서 링크를 승인 데이터에 대한 액세스를 허용하고 토큰을 얻을 것이다 다음 단계에 필요합니다.
authorization_code = code # authorization code taken from the previous step
client = OAuth2::Client.new(
"www.googleapis.com",
client_id,
client_secret,
token_uri: "/oauth2/v4/token",
redirect_uri: redirect_uri
)
access_token = client.get_access_token_using_authorization_code(authorization_code)
client = HTTP::Client.new("people.googleapis.com", tls: true)
access_token.authenticate(client)
response = client.get "/v1/people/me?personFields=names"
response.body # a json that contains my name