谷歌不喜欢我的WAMP服务器。有人有主意吗?

时间:2012-04-06 19:49:57

标签: php curl http-post google-api

好吧,我在这里的绳子尽头。我已经尝试过几乎所有尝试让这个工作。我之前已经在网络主机上完成了Google OAUTH API调用,一切都运行良好,但是当我在WAMP服务器上使用相同的脚本时,谷歌不会回复我的cURL帖子。我已经通过发布到我自己的服务器以及有人设置的服务器测试了cURL帖子:

http://www.newburghschools.org/testfolder/dump.php

它运作得很好。这是我让用户允许我的应用程序之后使用的脚本:

<?

//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/");  
}

?>

当我回应出应该是谷歌的回应时,我得到的只是一个单数的“/”。当我在我的webhost上运行这个完全相同的脚本时,在更改DNS IP后,它工作正常。我想谷歌不喜欢我的WAMP服务器,甚至不会和它说话,或者可能是我的cURL配置。在WAMP服务器上无法为Google API开发只是一个小麻烦,但如果有人有任何想法,我们将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:1)

我从FALSE收到了curl_exec(),但这是我修复它的方式:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

http://us3.php.net/manual/en/function.curl-setopt.php

希望这有帮助!