0
votes

here's my problem, i hope someone can help me :(

Problem Description: I make a PHPscript to backup every day Google/Gmail contacts from a account. I get a atom file but i want a google_csv file.

Steps to Reproduce: After authentication (OAuth v3) API i get contactList with POST https://www.google.com/m8/feeds/contacts/default/full?access_token=XXXXXXXXX. So i get a ATOM file but I want extract a google csv (with group....)

I try with - contacts/default/full?alt=csv&access_token=XXXXXXXXX (KO) - contacts/default/full?alt=google_csv&access_token=XXXXXXXXX (KO) - contacts/default/full?out=google_csv&access_token=XXXXXXXXX (KO) - https://www.google.com/s2/u/0/data/exportquery?ac=false&cr=true&ct=true&ev=true&f=g2&gp=true&hl=fr&id=personal&max=-1&nge=true&out=google_csv&sf=display&sgids=6%2Cd%2Ce%2Cf%2C17&st=0&type=4&tok=XXXXXXXXX (KO) ...

Is there any suggestion to convert atom file to google_csv file ? OR to directly get a google_csv with a exportquery from google ?

Thanks

1

1 Answers

0
votes

Based from this SO ticket, you need to have a csv file that is a table, with well defined columns and the same number of columns in each row.

The script below will show you how to get the google contacts in .csv file. You need to get the data in form of string and use the scripts for printing them for spread sheet format.

<?php

$data = $_POST['email'];

$arry[] = explode(',', $data);

foreach ($arry as $row) 
{
    $arlength = count($row);
    for ($i = 0; $i < $arlength; $i++) 
    {
    $farry[] = explode(',', $row[$i]);
    }
}

header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");

$file = fopen('php://output', 'w');
fputcsv($file, array('Description'));
foreach ($farry as $row) 
{
    fputcsv($file, $row);
}

exit();

Check this tutorial.