Google Api PHP Client Library

自作多情 提交于 2019-12-06 05:11:17
Michael Valentino

You have to configure proxy settings in curl. Check Google_CurlIO.php for a line that calls curl_exec($ch).

You may need to add something beforehand similar to:

curl_setopt($ch, CURLOPT_PROXY, 'your-proxy-server');

Just to add (Since I wasn't able to find any results in google for this) if you want to avoid having to edit the library itself you can specify the additional curl params via the $client object. The code to do so looks roughly like this.

$client = new Google_Client();
$client->getIo()->setOptions(array(
    CURLOPT_PROXY => 'myproxy.mywebsite.com',
    CURLOPT_PROXYPORT => 8909
));

Update for v2.0.0

$client = new Google_Client();
$httpClient = $client->getHttpClient();
$httpClient->setDefaultOption("proxy", "http://{$proxyUser}:{$proxyPass}@{$proxyAddress}:{$proxyPort}");

Update for version 2.2.0

The library uses Guzzle which reads the environnement variables to automatically setup (or not) a proxy (see GuzzleHttp\Client class) line 177:

    if ($proxy = getenv('HTTPS_PROXY')) {
        $defaults['proxy']['https'] = $proxy;
    }

I assume you need a HTTPS proxy since Google OAuth won't work over simple HTTP.

Just add

putenv('HTTPS_PROXY=https://{your.proxy.url}:{port_number}');

and it works by itself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!