我在我的网络应用程序中集成了谷歌Adwords API,我在执行我的php文件时遇到错误,即
错误:
Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /var/www/vhosts/healthcampaign.in/httpdocs/smscampaign/pages/FacebookAds.php on line 187
SoapFault Object ( [message:protected] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com/api/adwords/cm/v201406/CampaignService?wsdl' :
failed to load external entity "https://adwords-sandbox.google.com/api/adwords/cm/v201406/CampaignService?wsdl"
[string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/vhosts/healthcampaign.in/httpdocs/smscampaign/pages/FacebookAds.php [line:protected] => 219
[trace:Exception:private] => Array ( [0] => Array (
[file] => /var/www/vhosts/healthcampaign.in/httpdocs/smscampaign/pages/FacebookAds.php [line] => 219
[function] => SoapClient
[class] => SoapClient
[type] => -> [args] => Array (
[0] => https://adwords-sandbox.google.com/api/adwords/cm/v201406/CampaignService?wsdl
[1] => Array ( [trace] => 1 )
)
)
)
[previous:Exception:private] => [faultstring] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com/api/adwords/cm/v201406/CampaignService?wsdl' :
failed to load external entity "https://adwords-sandbox.google.com/api/adwords/cm/v201406/CampaignService?wsdl" [faultcode] => WSDL )
答案 0 :(得分:2)
问题出在SSL上。如果您在本地测试API并收到此错误,请尝试快速检查 - 在AdWords PHP SDK中找到名为AdsSoapClientFactory.php
的文件,并在第142行更新以添加&& false
:
// SSL settings.
if ($soapSettings->getSslVerify() === true && false) { // explicitly disable SSL Verify
代码行下面还有一些有用的注释。当然,不建议对生产系统禁用SSL验证,但至少这可以是一个快速的解决方案,不要忘记为什么该死的API不想工作。
如果这确实解决了问题,请考虑使用SoapSettings实现它。撤消对AdsSoapClientFactory.php
的更改,并在主文件中添加:
use Google\AdsApi\Common\SoapSettingsBuilder;
[...]
$soapSettings= (new SoapSettingsBuilder())
->disableSslVerify()
->build();
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->withSoapSettings($soapSettings)
->build();