google-api - ColdFusion Google OAuth 获取访问 token 连接失败

标签 google-api coldfusion google-oauth coldfusion-2016

遵循 Ray Camden 中的示例.在我尝试获取访问 token 之前一切都很好。我的 getAccessToken() 函数出现“连接失败”错误。不知道我做错了什么?

<cfset authurl = "https://accounts.google.com/o/oauth2/v2/auth?" & 
"client_id=#urlEncodedFormat(application.clientid)#" & 
"&redirect_uri=#urlEncodedFormat(application.callback)#" & 
"&scope=https://www.googleapis.com/auth/userinfo.profile&response_type=code"> 
<cfoutput> 
authurl=#authurl#
<p><a href="#authurl#">Login</a></p> 
</cfoutput>

<cffunction name="getAccessToken"> 
<cfargument name="code" required="false" default="" type="string">
<cfset var postBody = "code=" & UrlEncodedFormat(arguments.code) & "&"> 
<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(this.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(this.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(this.callback) & "&"> 
<cfset postBody = postBody & "grant_type=authorization_code">

<cfhttp method="post" url="https://www.googleapis.com/oauth2/v4/token"> 
<cfhttpparam type="header" name="Content-Type"  value="application/x-www-form-urlencoded"> 
<cfhttpparam type="body" value="#postBody#">     
</cfhttp>   
<cfreturn deserializeJSON(cfhttp.filecontent.tostring())>

最佳答案

替换行

<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(this.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(this.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(this.callback) & "&"> 

<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(application.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(application.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(application.callback) & "&"> 

关于google-api - ColdFusion Google OAuth 获取访问 token 连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53121466/

相关文章:

java - 我是否需要 G Suite 帐户才能通过服务帐户冒充用户发出请求?

javascript - GoogleMaps getLatLng 你的意思是建议吗

xml - ColdFusion:无效的 XML 控制字符(十六进制)

java - 错误 : while connecting Google Cloud Storage using Java => java.net.UnknownHostException : oauth2. googleapis.com

javascript - 当表中有多个记录时,在 JS 中获取隐藏值时出现问题(Coldfusion)

php - 切换到 ColdFusion?

java - 我是否必须在访问公共(public)工作表的 Java 客户端应用程序中使用默认的 google API 身份验证?

php - 即使出现 fatal error : Uncaught exception也继续

google-api - Facebook SDK + 谷歌 SDK : The frame being accessed set 'document.domain' to 'facebook.com'

node.js - Google API 服务帐户 - 无法访问私有(private)数据