在Coldfusion中使用gmail帐户登录

时间:2013-06-28 11:19:24

标签: coldfusion google-api coldfusion-9 google-login

我想使用gmail / google帐户登录,我找到了这个教程Gmail Login in Coldfusion。我完成了所有步骤,登录后我的页面重定向,然后我想显示用户配置文件信息,所以我转储了这个

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

但是它给了我一个空数组。为什么我在成功停用后没有得到我的个人资料数据。 如果我错误地获取我的个人资料,那么正确的方法是什么。感谢。

1 个答案:

答案 0 :(得分:1)

您只需将此行添加到scope 打开Application.cfc,然后添加此代码 使用scope = "https://www.googleapis.com/auth/analytics.readonly"

更改scope = "https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile

你可以添加scope = "https://www.googleapis.com/auth/userinfo.profile但是如果你想访问电子邮件,那么在我的回答中添加第二个作为我发布的内容。

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

希望这会对你有所帮助。

相关问题