1

我想使用 gmail/google 帐户登录,我在 Coldfusion 中找到了本教程 Gmail 登录。我完成了所有步骤,登录后我的页面重定向然后我想显示用户个人资料信息,所以我转储了这个

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

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

4

1 回答 1

1

您只需将此行添加到您的scope Open your 中,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>

希望这会帮助你。

于 2013-06-28T19:04:00.167 回答