[英]Google doesn't like my WAMP server. Anyone have any ideas?
Alright I'm at the end of the rope here.好吧,我已经到了穷途末路了。 I've tried just about everything to try to get this working.
我已经尝试了几乎所有方法来使它正常工作。 I've done Google OAUTH API calls before on web hosts and everything works great, but when I use the same scripts on my WAMP server, google does not reply to my cURL posts.
我之前在 web 主机上完成了 Google OAUTH API 调用,一切正常,但是当我在我的 WAMP 服务器上使用相同的脚本时,谷歌不会回复我的 cURL 帖子。 I've tested cURL post by posting to my own server as well as to this server someone set up:
我已经测试了 cURL 帖子,方法是发布到我自己的服务器以及有人设置的这个服务器:
http://www.newburghschools.org/testfolder/dump.php http://www.newburghschools.org/testfolder/dump.php
And it works just fine.它工作得很好。 Here's the script I'm using after I get the user to allow my application:
这是我在让用户允许我的应用程序后使用的脚本:
<?
//This script handles the response from google. If the user as authed the app, it will continue the process by formulating another URL request to Google to get the users information. If there was an error, it will simply redirect to index.
include_once($_SERVER['DOCUMENT_ROOT']."/../src/php/google/initialize.php");
if (!isset($_GET['error'])) {
//No error found, formulate next HTTP post request to get our auth token
//Set URL and get our data encoded for POST
$url = "https://accounts.google.com/o/oauth2/token";
$fields = array(
'code' => $_GET['code'],
'client_id' => $google['clientID'],
'client_secret' => $google['clientSecret'],
'redirect_uri' => "http://www.dealertec.com/scripts/php/google/reg_response.php",
'grant_type' => "authorization_code"
);
//$data = http_build_query($fields);
$data = "code=".$fields['code'].'&client_id='.$fields['client_id'].'&client_secret='.$fields['client_secret'].'&redirect_uri='.$fields['redirect_uri'].'&grant_type='.$fields['grant_type'];
echo $data."<br> /";
//Begin cURL function
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
//Decode the JSON and use it to make a request for user information
print_r($response);
$response = json_decode($response, true);
/*if (!isset($response['error'])) {
//No error in response, procede with final step of acquiring users information
$apiURL = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=".$response['access_token'];
$apiCall = curl_init($apiURL);
curl_setopt($apiCall, CURLOPT_RETURNTRANSFER, true);
curl_setopt($apiCall, CURLOPT_HEADER, false);
$apiResponse = curl_exec($apiCall);
$apiResponse = json_decode($apiResponse, true);
var_dump($apiResponse);
}else{
echo $response['error'];
}*/
}else{
header("LOCATION: http://www.dealertec.com/");
}
?>
When I echo out what is supposed to be the google response, all I get is a singular "/".当我回显应该是谷歌响应的内容时,我得到的只是一个单数“/”。 When I run this same exact script on my webhost, after changing back the DNS IP, it works fine.
当我在我的虚拟主机上运行完全相同的脚本时,在改回 DNS IP 后,它工作正常。 I'm thinking either Google doesn't like my WAMP server and won't even talk to it, or perhaps it's something with my cURL configuration.
我在想,要么是 Google 不喜欢我的 WAMP 服务器,甚至不愿与其交谈,要么是我的 cURL 配置有问题。 It's only a minor annoyance not being able to develop for Google API on my WAMP server, but if anyone has any ideas whatsoever, it would be greatly appreciated.
无法在我的 WAMP 服务器上为 Google API 开发只是一个小烦恼,但如果有人有任何想法,我们将不胜感激。
Thanks!谢谢!
I was getting a FALSE
coming back from curl_exec()
, but this is how I fixed it:我从
curl_exec()
返回一个FALSE
,但这就是我修复它的方式:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
http://us3.php.net/manual/en/function.curl-setopt.php http://us3.php.net/manual/en/function.curl-setopt.php
hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.