I am getting this error message intermittently when i am running GetRelatedKeywords.php. Failed to get authToken. Reason....

3,377 views
Skip to first unread message

Blode Wong

unread,
Aug 8, 2012, 2:02:43 AM8/8/12
to adwor...@googlegroups.com

I am getting this error message intermittently when i am running GetRelatedKeywords.php.

The Error Message is:
"Failed to get authToken. Reason: Failed to connect to 2607:f8b0:4007:801::1010: Network is unreachable"

Can anyone help me out?

Blode Wong

unread,
Aug 9, 2012, 6:47:41 AM8/9/12
to adwor...@googlegroups.com
can anyone help me ?
在 2012年8月8日星期三UTC+8上午10时02分43秒,Blode Wong写道:

Anash P. Oommen

unread,
Aug 10, 2012, 8:38:55 AM8/10/12
to adwor...@googlegroups.com
Hi,

This looks like a network issue at your end, you might want to investigate if your internet connection is flaky, most likely at your network or ISP level.

Cheers,
Anash P. Oommen,
AdWords API Advisor.

Peter Crowley

unread,
Aug 10, 2012, 11:36:38 AM8/10/12
to adwor...@googlegroups.com
I have been getting this message also. For several months. I assume something changed with my ISP. I have to reload the page several times & then it executes.

In case it helps my PHP version details are:
PHP 5.2.17 with Suhosin-Patch 0.9.7 (cgi-fcgi) (built: May 29 2012 13:34:52)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

and my OS details are:
Linux 
2.6.32-20120131.55.1.bh6.x86_64 
#1 SMP Tue Jan 31 15:3:27 EST 2012 
x86_64 x86_64 x86_64 GNU/Linux

-Peter

Lucas Schultze

unread,
Aug 15, 2012, 8:55:56 PM8/15/12
to adwor...@googlegroups.com
I am also having this same issue.  I'm running the API on a share webhost.  I had originally thought it was an IPv6 issue with cURL.  At a loss.  I am thinking I am going to have to move this script to another host. 

Blode Wong

unread,
Aug 17, 2012, 9:04:53 AM8/17/12
to adwor...@googlegroups.com
thanks for your reply.

I was testing in several network environment, but this problem is all the same.

Blode Wong

unread,
Aug 17, 2012, 9:11:04 AM8/17/12
to adwor...@googlegroups.com, sch...@gmail.com
Hello, Lucas Schltze.

Thanks for your reply first.

I am running this script ina share web hosting too.  so i was testing in serveral environment just like bluehost, justhost, godaddy etc. but the results is the same!

BTW: The script is running fine about 2 months ago.

Blode Wong

unread,
Aug 17, 2012, 9:33:18 AM8/17/12
to adwor...@googlegroups.com
important informations:

when i move this script to a new network environment, it's running fine at the first time.

Is it need cache the authToken?

Danial Klimkin

unread,
Aug 21, 2012, 8:46:30 AM8/21/12
to adwor...@googlegroups.com
Hello Blode,


Please make sure your firewall allows outbound connections to google.com on HTTPS port (443). For example, try opening this link with curl / wget / lynx from server console:



-Danial, AdWords API Team.

Peter Crowley

unread,
Aug 21, 2012, 11:18:25 AM8/21/12
to adwor...@googlegroups.com
Hi  Daniel,
    I put this Curl code in after the 'require_once' but before the 'new AdWordsUser'

$curl = curl_init();
$file = fopen($localfile, 'w');
curl_setopt($curl, CURLOPT_URL, "https://google.com"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
if (curl_exec($curl) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'HTTPs test worked',$newline;
}


It did not help, I got this output on first run, then it worked when I reloaded(F5'd) the page.

/home1/mysite/public_html/ads/googlehomepage.html
HTTPs test worked
Exception: Failed to get authToken. Reason: Failed to connect to 2607:f8b0:400e:c01::54: Network is unreachable in line 84 file /home1/mysite/public_html/libraries/aw_api_php/src/Google/Api/Ads/Common/Util/AuthToken.php 

Danial Klimkin

unread,
Aug 22, 2012, 12:31:52 PM8/22/12
to adwor...@googlegroups.com
Hello Peter,


Is your php compiled with the ssl support enabled? This can be controlled differently for different OS distributions. It could be checked with:

$ php -i | grep -i ssl


-Danial, AdWords API Team.

Peter Crowley

unread,
Aug 23, 2012, 1:47:43 PM8/23/12
to adwor...@googlegroups.com
Yes, it looks like SSL is enabled...output from ' php -i | grep -i ssl':

openssl

OpenSSL support enabled OpenSSL Version OpenSSL 1.0.0-fips 29 Mar 2010 SSL support enabled 

Eric Koleda

unread,
Aug 23, 2012, 2:47:04 PM8/23/12
to adwor...@googlegroups.com
Hi All,

I believe Lucas is correct, that this issue is related to IPv6.  This article provides some details:


As the author listed, if you are using PHP 5.3 then there is a cURL option you can use to force IPv4:

curl_setopt( $handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

If not then you'll need to work with your hosting provider / ISP to properly configure your server/network to either support IPv6 or disable it. Please note this is not a problem specific to the AdWords API, and can be seen with other APIs as well:


The timing of this issue (about 2 months ago) corresponds with the IPv6 Launch Day on June 6th:


Best,
- Eric

Peter Crowley

unread,
Aug 25, 2012, 7:38:26 AM8/25/12
to adwor...@googlegroups.com
Hi Eric,
   Thanks for all the details.
   My PHP version is 5.2.17 so the cURL option will not work. 
I will send an update explaining which path I took when I get there.

-Peter

Evgeniy Bogdanov

unread,
Aug 27, 2012, 10:57:01 PM8/27/12
to adwor...@googlegroups.com
Hi Peter.

If you still have this problem,buzz me tomorrow (28th August) in Skype between 14.00 and 17.00 MSK. I'll try to save your time and nerves and help to solve this strange problem.

Regards,
Evgeniy.

Blode Wong

unread,
Aug 28, 2012, 1:52:12 AM8/28/12
to adwor...@googlegroups.com
Hi, Thanks to all.
 
I have solved this problem. It is caused by IPV6.
 
now , i have moved my script to another web hosting in China,  then it's running fine.
 
thanks to all again!
 
>>> to Eric:
 
this article is very useful! thanks.

On Wednesday, August 8, 2012 10:02:43 AM UTC+8, Blode Wong wrote:

Evgeniy Bogdanov

unread,
Aug 28, 2012, 2:32:08 PM8/28/12
to adwor...@googlegroups.com
If you meet with this such problem the best way is to upgrade PHP and libcurl to latest versions. If you can't do this, you can apply next fix:
file: src/Google/Api/Ads/Common/Util/AuthToken,php,
function Login()

add below:
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);

next strings:
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
} else {
    curl_setopt($ch, CURLOPT_URL, str_replace('accounts.google.com', '74.125.127.84', $postUrl));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: accounts.google.com'));
}

Some explanation how it works: we're change hostname to IP address in URI to prevent cURL perform DNS lookup.
But we need somehow to specify which host we're requesting for, so we're adding manually our end Host in HTTP Header.

This is not best practice, but gives you time to keep your scripts working till you didn't find way to upgrade PHP or move to other server.

Regards,
Evgeniy.

Lucas Schultze

unread,
Sep 12, 2012, 1:57:51 AM9/12/12
to adwor...@googlegroups.com
Depends on your webhost.  I use hostmonster and their support gave me that answer that they currently don't support IPV6 connections to external 3rd parties.  

 The 'CURL_IPRESOLVE_V4' was throwing errors when I tried to use it.  Seems like it was added to one of the most recent versions of PHP.  

My solution has also been to move my adwords API script to new host.  

RPC

unread,
Feb 1, 2013, 6:44:15 AM2/1/13
to adwor...@googlegroups.com, blo...@gmail.com
We're getting this error with Bluehost.

Are there any new fixes and if not can anyone recommend hosts that work without any of these issues?

Thanks - R.

Evgeniy Bogdanov

unread,
Feb 4, 2013, 7:39:32 AM2/4/13
to adwor...@googlegroups.com, blo...@gmail.com
Hi R.

My previous fix in this thread do not works for you?

Can you create test account for me on your current host? I'll try to improve it.

пятница, 1 февраля 2013 г., 10:44:15 UTC+4 пользователь RPC написал:

RPC

unread,
Feb 4, 2013, 9:44:35 AM2/4/13
to adwor...@googlegroups.com, blo...@gmail.com
Unfortunately Bluehost doesn't let you create extra login accounts. I spoke to their tech support last week and they said "that's a good idea, I'll suggest it". Duh.

Best option is FTP access. Not sure is that is enough?

Anyhow I've asked the developer whether he has in fact tried all of your solutions and I expect an answer soon

I still think the best option is to move host - who do you use?

R.

Evgeniy Bogdanov

unread,
Feb 4, 2013, 11:31:49 AM2/4/13
to adwor...@googlegroups.com, blo...@gmail.com
I can use FTp, if you agree. I'm interested to improve my solution to support most of PHP configuration. But unfortunately I can't re-implement them on my hosts.

I'm prefer to not use hosting, I like virtual servers for their flexibility in setup. For example http://www.rackspace.com/

If you will move to other host, can you not terminate current subscription and give me access for it?

Regards,
Evgeniy.

понедельник, 4 февраля 2013 г., 13:44:35 UTC+4 пользователь RPC написал:

Evgeniy Bogdanov

unread,
Feb 6, 2013, 9:11:51 AM2/6/13
to adwor...@googlegroups.com, blo...@gmail.com
OK. Thanks RPC for giving me access for his host.
I've improved my previous solution:

Library version: 3.2.2
File: src/Google/Api/Ads/Common/Util/AuthToken.php,
Function: private function Login()

Add after:
$this->curlUtils->SetOpt($ch, CURLOPT_POSTFIELDS, $postVars);

Next strings:

if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
    $this->curlUtils->SetOpt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
} else {
    $hostInfo = parse_url($this->server);
    if (!empty($hostInfo['host'])) {
    $this->curlUtils->SetOpt($ch, CURLOPT_URL, str_replace($hostInfo['host'], '74.125.143.84', $postUrl));
    $this->curlUtils->SetOpt($ch, CURLOPT_HTTPHEADER, array('Host: ' . $hostInfo['host']));
    }
}

I think that usage of this fix is not good for production servers.
Main problem here that we're using direct IP-address, not DNS-name, this can cause unexpected & not predictable problems in future.

If someone will get error like: unable to connect to host using this fix, you need to change 74.125.143.84 to new IP-address.
You can do it via operating system nslookup command. 
Type nslookup accounts.google.com, you'll get address which should be used.

Regards,
Evgeniy.

MCC Test

unread,
Feb 20, 2015, 9:53:51 AM2/20/15
to adwor...@googlegroups.com
Hello,

Recently I got same issue as "Failed to connect to 2607:f8b0:4007:808::200d: Network is unreachable" code is hosted on hostmonster shared hosting.

Please help me to solve this issue.

Thanks,
Ronak Shah

kalpesh tawde

unread,
Aug 10, 2015, 12:59:25 PM8/10/15
to AdWords API Forum
This code has solve my problem.

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

Regards,
Kalpesh
Reply all
Reply to author
Forward
0 new messages