0

好吧,我已经走到了尽头。我已经尝试了几乎所有方法来尝试使其正常工作。我之前在网络主机上进行过 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/");  
}

?>

当我回显应该是谷歌响应时,我得到的只是一个单数“/”。当我在我的虚拟主机上运行相同的脚本时,在更改回 DNS IP 后,它工作正常。我在想 Google 不喜欢我的 WAMP 服务器,甚至不会与之交谈,或者可能是我的 cURL 配置的问题。无法在我的 WAMP 服务器上为 Google API 开发只是一个小烦恼,但如果有人有任何想法,将不胜感激。

谢谢!

4

1 回答 1

1

FALSE从 回来了curl_exec(),但这就是我修复它的方法:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

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

希望这可以帮助!

于 2012-04-06T23:59:12.057 回答