2013-06-28 5 views
1

Gmail/Google 계정으로 로그인하고 싶습니다.이 자습서는 Gmail Login in Coldfusion입니다. 그래서이Coldfusion에서 Gmail 계정으로 로그인

<cfdump var="#session.profilesArray#"> 

덤프하지만 나에게 내가 성공적으로 LO- 후 내 프로필 데이터를 받고 있지 않다 빈 array.why를 제공합니다 나는 모든 단계를 완료하고 로그인 후 마이 페이지 내가 사용자 프로필 정보를 표시 할 다음 리디렉션 진. 내 프로필을 가져 오는 방법이 잘못 되었다면 올바른 방법은 무엇입니까? 감사.

당신은 당신의 Application.cfc을 열고 당신의 scope 에이 줄을 추가 한 다음 방금 scope = "https://www.googleapis.com/auth/userinfo.profile을 추가하지만, u는 이메일에 액세스하려면 다음의 I 포스트로 두 번째를 추가 할 수 있습니다 scope = "https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile

이 코드를 변화 scope = "https://www.googleapis.com/auth/analytics.readonly"를 추가

+2

전체 세션 범위를 덤프하고 실제로 무엇이 있는지 확인하십시오. –

+0

내 전체 세션은'session.profilesArray'에 있습니다. 이 안에 있지 않니? –

+0

profilesArray가 전체 세션 범위가 아닙니다. '' –

답변

1

내 대답.

 <cfset request.oauthSettings = 
      {scope = "https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile", 
            client_id = "Your-id", 
            client_secret = "your-secret", 
            redirect_uri = "redirect-page", 
            state = "optional"} /> 

지금 당신은 당신이 당신을 도울 것이

<cfscript>    
     public function getProfile(accesstoken) { 

      var h = new com.adobe.coldfusion.http(); 
      h.setURL("https://www.googleapis.com/oauth2/v1/userinfo"); 
      h.setMethod("get"); 
      h.addParam(type="header",name="Authorization",value="OAuth #accesstoken#"); 
      h.addParam(type="header",name="GData-Version",value="3"); 
      h.setResolveURL(true); 
      var result = h.send().getPrefix(); 
      return deserializeJSON(result.filecontent.toString()); 
     }  
    </cfscript> 

      <cfoutput> 
      <cfset show = getProfile(session.ga_accessToken)> 
      <cfdump var="#show#"> 
      </cfoutput> 

희망처럼 호출 할 수있는 기능에서 사용자 정보를 얻을 수 있습니다.

+0

고마워. 내 문제를 해결하는 데 많은 도움이됩니다. –

관련 문제