Вопрос

I want to login with gmail/google account and I found this tutorial Gmail Login in Coldfusion. I done All the steps and After login my page redirect then I want to display user Profile information so I dump this

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

but it gives me an empty array.why I am not getting my profile data after successfully lo-gin. If I am getting wrong way for fetching my profile then what is correct way. Thanks.

Это было полезно?

Решение

You just add this line into your scope Open your Application.cfc and then add this code change scope = "https://www.googleapis.com/auth/analytics.readonly" with scope = "https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile

you can just add scope = "https://www.googleapis.com/auth/userinfo.profile but if u want to access email then add second one as I Post in my answer.

     <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"} />

Now you can get User Information from function that you can call like this

    <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>

Hope this will help you.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top