Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api ColdFusion Google OAuth获取访问令牌连接失败_Google Api_Coldfusion_Google Oauth_Coldfusion 2016 - Fatal编程技术网

Google api ColdFusion Google OAuth获取访问令牌连接失败

Google api ColdFusion Google OAuth获取访问令牌连接失败,google-api,coldfusion,google-oauth,coldfusion-2016,Google Api,Coldfusion,Google Oauth,Coldfusion 2016,下面的例子来自。在我尝试获取访问令牌之前,一切正常。我的getAccessToken()函数出现“连接失败”错误。不知道我做错了什么 <cfset authurl = "https://accounts.google.com/o/oauth2/v2/auth?" & "client_id=#urlEncodedFormat(application.clientid)#" & "&redirect_uri=#urlEncodedFormat(application

下面的例子来自。在我尝试获取访问令牌之前,一切正常。我的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())>

authurl=#authurl#

更换线路

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



您可以访问
https://www.googleapis.com
来自ColdFusion服务器?这很可能与使用cfhttp通过SSL(https)进行连接有关。看看这个答案,可以得到详细的解释,祝你好运!谢谢你们两位!你提供的链接上的说明解决了这个问题!
<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(application.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(application.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(application.callback) & "&">