Skip to content
Advertisement

PHP – read CSV from Google Sheets but sheets redirect to login

I have created several sheets in Google Sheets that I’m retrieving with a CSV output through PHP. It was all working fine until today while I have not changed anything to my code.

I was using this:

if (($handle = fopen($sheet_url, "r")) !== FALSE) 
{
    while (($data = fgetcsv($handle, 3000, ",")) !== FALSE) 
        {
           // BLA BLA
        }
 }

It was working fine. If I try to access my sheet directly through the browser I get a CSV file in return but hitting it through PHP is not working anymore.

I have unpublished the sheet and republished it. I have checked my php.ini and it allows fetching urls.

I then tried to use cURL and I discovered that when download the sheet with PHP, I don’t get my sheet in return, I get a login page instead while I have published the sheet for everyone.

I have found a blog explaining the same thing, the blogger solved this by adding a &ndplr=1 to the sheet url but it doesn’t help.

I don’t understand why Google Sheets suddenly need a login when using PHP.

Do you have any idea?

Thanks

Advertisement

Answer

Apparentely, it’s a global problem that has started a few days ago, there are many other complaints on Google support sites.

The only way around today is to open/reopen the Google Sheets to anyone (through the sharing button)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement