Fastest Web Hosting

how to update gmail contact by google api in php

0 votes
asked Sep 30, 2016 in PHP by vinod.kumar (520 points)

I am using Google client API for getting gmail contact in php. I have create code for add and delete gmail contact API in php but I could not find any API by which I can update any contact in Gmail using Google contact Apin php.

Please help me regarding this.

I have use below code

require_once 'google-api-php-client-1-master/src/Google/autoload.php'; $client = new Google_Client(); $client -> setApplicationName('Gmail Contact'); $client -> setClientid($google_client_id); $client -> setClientSecret($google_client_secret); $client -> setRedirectUri($google_redirect_uri); $client -> setAccessType('offline'); $client -> setApprovalPrompt('force');
$fname = 'testing fname';
    $lname = 'test lname';
    $uemail = 'jim@gmail.com';  
    $uphone = 98651245; 
    $updateXML = '<?xml version="1.0" encoding="utf-8"?>
        <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
        <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
        <gd:name>
        <gd:givenName>'.$fname.'</gd:givenName>
        <gd:fullName>'.$fname.' '.$lname.'</gd:fullName>
        <gd:familyName>'.$lname.'</gd:familyName>
        </gd:name>
        <gd:email rel="http://schemas.google.com/g/2005#home" address="'.$uemail.'"/>       
        </atom:entry>';

    $headers = array(
        'If-Match: Etag',
        'Gdata-version: 3.0',
        'Content-Type: application/atom+xml',
        'Authorization: OAuth '.$accesstoken
    );

    $contacturl = 'https://www.google.com/m8/feeds/contacts/vinodkumar.mobifly@gmail.com/full/{'.$contckey.'}';


    $chupp = curl_init();
    curl_setopt($chupp, CURLOPT_URL, $contacturl );
    curl_setopt($chupp, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($chupp, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($chupp, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($chupp, CURLOPT_POSTFIELDS, $updateXML);
    curl_setopt($chupp, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($chupp, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($chupp, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($chupp, CURLOPT_TIMEOUT, 10);
    curl_setopt($chupp, CURLOPT_FAILONERROR, true);
    $inserarray=curl_exec($chupp);
    curl_close($chupp);

1 Answer

0 votes
answered Apr 4 by anonymous

Hi vinoth,

Can you please suggest me how to delete the existing google contacts ....

Job Board

TechnicalSharp is a technical community of developers where they are sharing their knowledge and solutions and against it they are getting the score point which help them to make profile strong which is under eyes on MNC's
...