2017-04-19 10 views
1

Google Dll없이 Gmail API를 사용하려고하며 HTTP 요청에만 사용하고 싶습니다. Google dll로 서비스를 만드는 등의 방법으로 범위를 인증하고 권한을 부여하려면 어떻게해야합니까?Google Dll없이 Gmail API를 인증하는 방법

enter image description here

난 당신이 HTTP의 POST 및 HTTP GET을 처리 할 수있는 어떤 언어를 사용하여 Google에 인증 할 수 있습니다

enter image description here

답변

1

오류를 얻고있다.

참고 : client_id, redirect_uri, client_secret은 모두 Google Developers Console에서 앱에 대해 설정 한 값입니다. 범위는 액세스하려는 Google Api에 따라 달라지며 그 중 하나는 쉼표로 구분할 수 있습니다. 이 예에서는 Google 애널리틱스의 범위를 사용합니다.

1 단계 요청 액세스 :

이렇게하면 사용자 액세스를 요청에 표시해야하는 URL입니다. 그것은 HTTP Get 호출이며 모든 웹 브라우저에 배치 할 수 있습니다. Note: response_type=code

https://accounts.google.com/o/oauth2/auth?client_id={clientid}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code 

2 단계 : 그들은 위의 링크를 클릭하면

당신이 인증 코드를 받아야합니다.

다음 요청은 액세스 토큰과 새로 고침 토큰에 대한 코드를 교환합니다. 새로 고침 토큰을 사용

{ "access_token" : "ya29.1.AADtN_VSBMC2Ga2lhxsTKjVQ_ROco8VbD6h01aj4PcKHLm6qvHbNtn-_BIzXMw", "token_type" : "Bearer", "expires_in" : 3600, "refresh_token" : "1/J-3zPA8XR1o_cXebV9sDKn_f5MTqaFhKFxH-3PUPiJ4" } 

:

위의 요청에서 얻는 access_token은 당신이 만들어 사용하게 될 것입니다 이것은 HTTP POST Note: grant_type=authorization_code

https://accounts.google.com/o/oauth2/token 
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code 

반응이다 서비스 요청.

{ "access_token" : "ya29.1.AADtN_XK16As2ZHlScqOxGtntIlevNcasMSPwGiE3pe5ANZfrmJTcsI3ZtAjv4sDrPDRnQ", "token_type" : "Bearer", "expires_in" : 3600 } 
: Note: grant_type=refresh_token

https://accounts.google.com/o/oauth2/token 
client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&refresh_token=1/ffYmfI0sjR54Ft9oupubLzrJhD1hZS5tWQcyAvNECCA&grant_type=refresh_token 

이는 반응이다 : 한 시간 액세스 토큰이 만료됩니다 이후에 당신은 당신이 위에있어 refresh_token도 및 HTTP 포스트 받아 새로운 access_token이를 요청해야합니다

내 전체 튜토리얼 Google 3 legged oauth2 flow

사용 :

그냥 압정 access_token은 = yourtoken가 마지막에 사용하고자하는 당신이 액세스 권한이 Gmail의 API에 대한 모든 요청.

또는 헤더를 설정할 수 있습니다.

Authorization Bearer accessToken 
+1

감사합니다.그게 정확히 내가 찾던 것이 었습니다. – kostas

+0

다음은 Gmail 범위 목록입니다. https://developers.google.com/gmail/api/auth/scopes Gmail에 대한 참고 사항. 테스트 및 개발 중에 가짜 Gmail 계정을 사용하십시오. 당신은 실제 이메일 계정이 야생으로 돌아가는 루프를 가지고 있다면 금지하고 싶다. – DaImTo

+0

나는이 URL ** https : //accounts.google.com/을 사용하는 코드를 성공적으로받은 후 토큰을 가져 가려고 할 때/oauth2/토큰? 코드 = {code받은} & client_id = {myclient id} .apps.googleusercontent.com & client_secret = {mmy secret} & redirect_uri = urn : ietf : wg : oauth : 2.0 : oob & grant_type = authorization_code **하지만 유효하지 않은 요청 메시지. – kostas