public function execute() { $body = ''; /** @var Google_Http_Request $req */ foreach ($this->requests as $key => $req) { $body .= "--{$this->boundary}\n"; $body .= $req->toBatchString($key) . "\n\n"; $this->expected_classes["response-" . $key] = $req->getExpectedClass(); } $body .= "--{$this->boundary}--"; $url = $this->root_url . '/' . $this->batch_path; $httpRequest = new Google_Http_Request($url, 'POST'); $httpRequest->setRequestHeaders(array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)); $httpRequest->setPostBody($body); $response = $this->client->getIo()->makeRequest($httpRequest); return $this->parseResponse($response); }
/** * @param $meta * @param $params * @return array|bool * @visible for testing */ private function process() { $postBody = false; $contentType = false; $meta = $this->request->getPostBody(); $meta = is_string($meta) ? json_decode($meta, true) : $meta; $uploadType = $this->getUploadType($meta); $this->request->setQueryParam('uploadType', $uploadType); $this->transformToUploadUrl(); $mimeType = $this->mimeType ? $this->mimeType : $this->request->getRequestHeader('content-type'); if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { $contentType = $mimeType; $postBody = is_string($meta) ? $meta : json_encode($meta); } else if (self::UPLOAD_MEDIA_TYPE == $uploadType) { $contentType = $mimeType; $postBody = $this->data; } else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) { // This is a multipart/related upload. $boundary = $this->boundary ? $this->boundary : mt_rand(); $boundary = str_replace('"', '', $boundary); $contentType = 'multipart/related; boundary=' . $boundary; $related = "--$boundary\r\n"; $related .= "Content-Type: application/json; charset=UTF-8\r\n"; $related .= "\r\n" . json_encode($meta) . "\r\n"; $related .= "--$boundary\r\n"; $related .= "Content-Type: $mimeType\r\n"; $related .= "Content-Transfer-Encoding: base64\r\n"; $related .= "\r\n" . base64_encode($this->data) . "\r\n"; $related .= "--$boundary--"; $postBody = $related; } $this->request->setPostBody($postBody); if (isset($contentType) && $contentType) { $contentTypeHeader['content-type'] = $contentType; $this->request->setRequestHeaders($contentTypeHeader); } }
public function testProcess() { $client = $this->getClient(); $data = 'foo'; // Test data *only* uploads. $request = new Google_Http_Request('http://www.example.com', 'POST'); $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false); $this->assertEquals($data, $request->getPostBody()); // Test resumable (meta data) - we want to send the metadata, not the app data. $request = new Google_Http_Request('http://www.example.com', 'POST'); $reqData = json_encode("hello"); $request->setPostBody($reqData); $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, true); $this->assertEquals(json_decode($reqData), $request->getPostBody()); // Test multipart - we are sending encoded meta data and post data $request = new Google_Http_Request('http://www.example.com', 'POST'); $reqData = json_encode("hello"); $request->setPostBody($reqData); $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false); $this->assertContains($reqData, $request->getPostBody()); $this->assertContains(base64_encode($data), $request->getPostBody()); }
/** * TODO(ianbarber): This function needs simplifying. * @param $name * @param $arguments * @param $expected_class - optional, the expected class name * @return Google_Http_Request|expected_class * @throws Google_Exception */ public function call($name, $arguments, $expected_class = null) { if (!isset($this->methods[$name])) { $this->client->getLogger()->error('Service method unknown', array('service' => $this->serviceName, 'resource' => $this->resourceName, 'method' => $name)); throw new Google_Exception("Unknown function: " . "{$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery // document as parameter, but we abuse the param entry for storing it. $postBody = null; if (isset($parameters['postBody'])) { if ($parameters['postBody'] instanceof Google_Model) { // In the cases the post body is an existing object, we want // to use the smart method to create a simple object for // for JSONification. $parameters['postBody'] = $parameters['postBody']->toSimpleObject(); } else { if (is_object($parameters['postBody'])) { // If the post body is another kind of object, we will try and // wrangle it into a sensible format. $parameters['postBody'] = $this->convertToArrayAndStripNulls($parameters['postBody']); } } $postBody = json_encode($parameters['postBody']); unset($parameters['postBody']); } // TODO(ianbarber): optParams here probably should have been // handled already - this may well be redundant code. if (isset($parameters['optParams'])) { $optParams = $parameters['optParams']; unset($parameters['optParams']); $parameters = array_merge($parameters, $optParams); } if (!isset($method['parameters'])) { $method['parameters'] = array(); } $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { $this->client->getLogger()->error('Service parameter unknown', array('service' => $this->serviceName, 'resource' => $this->resourceName, 'method' => $name, 'parameter' => $key)); throw new Google_Exception("({$name}) unknown parameter: '{$key}'"); } } foreach ($method['parameters'] as $paramName => $paramSpec) { if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { $this->client->getLogger()->error('Service parameter missing', array('service' => $this->serviceName, 'resource' => $this->resourceName, 'method' => $name, 'parameter' => $paramName)); throw new Google_Exception("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; unset($parameters[$paramName]['required']); } else { // Ensure we don't pass nulls. unset($parameters[$paramName]); } } $this->client->getLogger()->info('Service Call', array('service' => $this->serviceName, 'resource' => $this->resourceName, 'method' => $name, 'arguments' => $parameters)); $url = Google_Http_REST::createRequestUri($this->servicePath, $method['path'], $parameters); $httpRequest = new Google_Http_Request($url, $method['httpMethod'], null, $postBody); if ($this->rootUrl) { $httpRequest->setBaseComponent($this->rootUrl); } else { $httpRequest->setBaseComponent($this->client->getBasePath()); } if ($postBody) { $contentTypeHeader = array(); $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8'; $httpRequest->setRequestHeaders($contentTypeHeader); $httpRequest->setPostBody($postBody); } $httpRequest = $this->client->getAuth()->sign($httpRequest); $httpRequest->setExpectedClass($expected_class); if (isset($parameters['data']) && ($parameters['uploadType']['value'] == 'media' || $parameters['uploadType']['value'] == 'multipart')) { // If we are doing a simple media upload, trigger that as a convenience. $mfu = new Google_Http_MediaFileUpload($this->client, $httpRequest, isset($parameters['mimeType']) ? $parameters['mimeType']['value'] : 'application/octet-stream', $parameters['data']['value']); } if (isset($parameters['alt']) && $parameters['alt']['value'] == 'media') { $httpRequest->enableExpectedRaw(); } if ($this->client->shouldDefer()) { // If we are in batch or upload mode, return the raw request. return $httpRequest; } return $this->client->execute($httpRequest); }
public function processEntityRequest($io, $client) { $req = new Google_Http_Request("http://localhost.com"); $req->setRequestMethod("POST"); // Verify that the content-length is calculated. $req->setPostBody("{}"); $io->processEntityRequest($req); $this->assertEquals(2, $req->getRequestHeader("content-length")); // Test an empty post body. $req->setPostBody(""); $io->processEntityRequest($req); $this->assertEquals(0, $req->getRequestHeader("content-length")); // Test a null post body. $req->setPostBody(null); $io->processEntityRequest($req); $this->assertEquals(0, $req->getRequestHeader("content-length")); // Set an array in the postbody, and verify that it is url-encoded. $req->setPostBody(array("a" => "1", "b" => 2)); $io->processEntityRequest($req); $this->assertEquals(7, $req->getRequestHeader("content-length")); $this->assertEquals(Google_IO_Abstract::FORM_URLENCODED, $req->getRequestHeader("content-type")); $this->assertEquals("a=1&b=2", $req->getPostBody()); // Verify that the content-type isn't reset. $payload = array("a" => "1", "b" => 2); $req->setPostBody($payload); $req->setRequestHeaders(array("content-type" => "multipart/form-data")); $io->processEntityRequest($req); $this->assertEquals("multipart/form-data", $req->getRequestHeader("content-type")); $this->assertEquals($payload, $req->getPostBody()); }
/** * @visible for testing * Process an http request that contains an enclosed entity. * @param Google_Http_Request $request * @return Google_Http_Request Processed request with the enclosed entity. */ public function processEntityRequest(Google_Http_Request $request) { $postBody = $request->getPostBody(); $contentType = $request->getRequestHeader("content-type"); // Set the default content-type as application/x-www-form-urlencoded. if (false == $contentType) { $contentType = self::FORM_URLENCODED; $request->setRequestHeaders(array('content-type' => $contentType)); } // Force the payload to match the content-type asserted in the header. if ($contentType == self::FORM_URLENCODED && is_array($postBody)) { $postBody = http_build_query($postBody, '', '&'); $request->setPostBody($postBody); } // Make sure the content-length header is set. if (!$postBody || is_string($postBody)) { $postsLength = strlen($postBody); $request->setRequestHeaders(array('content-length' => $postsLength)); } return $request; }
/** * TODO(ianbarber): This function needs simplifying. * * @param $name * @param $arguments * @param $expected_class - optional, the expected class name * * @throws Google_Exception * * @return Google_Http_Request|expected_class */ public function call($name, $arguments, $expected_class = null) { if (!isset($this->methods[$name])) { throw new Google_Exception('Unknown function: ' . "{$this->serviceName}->{$this->resourceName}->{$name}()"); } $method = $this->methods[$name]; $parameters = $arguments[0]; // postBody is a special case since it's not defined in the discovery // document as parameter, but we abuse the param entry for storing it. $postBody = null; if (isset($parameters['postBody'])) { if (is_object($parameters['postBody'])) { $parameters['postBody'] = $this->convertToArrayAndStripNulls($parameters['postBody']); } $postBody = json_encode($parameters['postBody']); unset($parameters['postBody']); } // TODO(ianbarber): optParams here probably should have been // handled already - this may well be redundant code. if (isset($parameters['optParams'])) { $optParams = $parameters['optParams']; unset($parameters['optParams']); $parameters = array_merge($parameters, $optParams); } if (!isset($method['parameters'])) { $method['parameters'] = []; } $method['parameters'] = array_merge($method['parameters'], $this->stackParameters); foreach ($parameters as $key => $val) { if ($key != 'postBody' && !isset($method['parameters'][$key])) { throw new Google_Exception("({$name}) unknown parameter: '{$key}'"); } } foreach ($method['parameters'] as $paramName => $paramSpec) { if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) { throw new Google_Exception("({$name}) missing required param: '{$paramName}'"); } if (isset($parameters[$paramName])) { $value = $parameters[$paramName]; $parameters[$paramName] = $paramSpec; $parameters[$paramName]['value'] = $value; unset($parameters[$paramName]['required']); } else { // Ensure we don't pass nulls. unset($parameters[$paramName]); } } $servicePath = $this->service->servicePath; $url = Google_Http_REST::createRequestUri($servicePath, $method['path'], $parameters); $httpRequest = new Google_Http_Request($this->client, $url, $method['httpMethod'], null, $postBody); if ($postBody) { $contentTypeHeader = []; $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8'; $httpRequest->setRequestHeaders($contentTypeHeader); $httpRequest->setPostBody($postBody); } $httpRequest = $this->client->getAuth()->sign($httpRequest); $httpRequest->setExpectedClass($expected_class); if (isset($parameters['data']) && ($parameters['uploadType']['value'] == 'media' || $parameters['uploadType']['value'] == 'multipart')) { // If we are doing a simple media upload, trigger that as a convenience. $mfu = new Google_Http_MediaFileUpload($this->client, $httpRequest, isset($parameters['mimeType']) ? $parameters['mimeType']['value'] : 'application/octet-stream', $parameters['data']['value']); } if ($this->client->shouldDefer()) { // If we are in batch or upload mode, return the raw request. return $httpRequest; } return $httpRequest->execute(); }
public static function create($name, $phoneNumber, $emailAddress) { $doc = new \DOMDocument(); $doc->formatOutput = true; $entry = $doc->createElement('atom:entry'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005'); $doc->appendChild($entry); $title = $doc->createElement('title', $name); $entry->appendChild($title); $email = $doc->createElement('gd:email'); $email->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); $email->setAttribute('address', $emailAddress); $entry->appendChild($email); $contact = $doc->createElement('gd:phoneNumber', $phoneNumber); $contact->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); $entry->appendChild($contact); $xmlToSend = $doc->saveXML(); $client = GoogleHelper::getClient(); $req = new \Google_Http_Request('https://www.google.com/m8/feeds/contacts/default/full'); $req->setRequestHeaders(array('content-type' => 'application/atom+xml; charset=UTF-8; type=feed')); $req->setRequestMethod('POST'); $req->setPostBody($xmlToSend); $val = $client->getAuth()->authenticatedRequest($req); $response = $val->getResponseBody(); $xmlContact = simplexml_load_string($response); $xmlContact->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005'); $xmlContactsEntry = $xmlContact; $contactDetails = array(); $contactDetails['id'] = (string) $xmlContactsEntry->id; $contactDetails['name'] = (string) $xmlContactsEntry->title; foreach ($xmlContactsEntry->children() as $key => $value) { $attributes = $value->attributes(); if ($key == 'link') { if ($attributes['rel'] == 'edit') { $contactDetails['editURL'] = (string) $attributes['href']; } elseif ($attributes['rel'] == 'self') { $contactDetails['selfURL'] = (string) $attributes['href']; } } } $contactGDNodes = $xmlContactsEntry->children('http://schemas.google.com/g/2005'); foreach ($contactGDNodes as $key => $value) { $attributes = $value->attributes(); if ($key == 'email') { $contactDetails[$key] = (string) $attributes['address']; } elseif ($key == 'organization') { $contactDetails[$key] = 'hello'; //$contactDetails[$key] = (string) $value->children()->current() ?: 'hello'; } else { $contactDetails[$key] = (string) $value; } } return new Contact($contactDetails); }
function araa_registration_process($data) { require_once __DIR__ . '/vendor/google-api-php-client/src/Google/autoload.php'; global $araa_au_states; global $araa_countries; global $wpdb; // Check the submission is valid. $nonce = isset($_POST['araa_nonce']) ? $_POST['araa_nonce'] : null; if (!wp_verify_nonce($nonce, 'araa_register')) { return new WP_Error('nonce', 'Your session has expired, please submit the form again'); } if (empty($data['first_name'])) { return new WP_Error('first_name', 'You must provide your first name'); } if (empty($data['last_name'])) { return new WP_Error('last_name', 'You must provide your last name'); } if (empty($data['email']) || !is_email($data['email'])) { return new WP_Error('email', 'You must provide a valid email address'); } if (empty($data['country']) || !array_key_exists($data['country'], $araa_countries)) { return new WP_Error('country', 'You must select a country'); } if (empty($data['address_1']) || empty($data['suburb'])) { return new WP_Error('address', 'You must provide your address'); } if ($data['country'] == 'AU') { if (empty($data['state_au']) || !array_key_exists($data['state_au'], $araa_au_states)) { return new WP_Error('state', 'You must select a state'); } } else { if (empty($data['state'])) { return new WP_Error('state', 'You must provide your state'); } } if (empty($data['postcode'])) { return new WP_Error('postcode', 'You must provide your postcode'); } if (araa_registration_is_spam($data)) { return new WP_Error('spam', 'Your registration submission has been classified as spam'); } $client = new Google_Client(); try { $client->setClientId(get_option('araa_client_id')); $client->setClientSecret(get_option('araa_client_secret')); $client->setAccessToken(get_option('araa_access_token')); } catch (Google_Auth_Exception $ex) { return new WP_Error('auth', 'A system error was encountered processing your registration. Please try again later.'); } if (araa_registration_is_duplicate($client, $data['email'])) { return new WP_Error('duplicate', 'A registration with this email address has already been submitted'); } // The registraion is valid, so write it to the sheet. $body = <<<EOS <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended"> <gsx:first_name>%s</gsx:first_name> <gsx:last_name>%s</gsx:last_name> <gsx:date>%s</gsx:date> <gsx:email>%s</gsx:email> <gsx:phone>%s</gsx:phone> <gsx:address_1>%s</gsx:address_1> <gsx:address_2>%s</gsx:address_2> <gsx:suburb>%s</gsx:suburb> <gsx:state>%s</gsx:state> <gsx:postcode>%s</gsx:postcode> <gsx:country>%s</gsx:country> </entry> EOS; $body = sprintf($body, esc_html($data['first_name']), esc_html($data['last_name']), esc_html(date('c')), esc_html($data['email']), esc_html($data['phone']), esc_html('')); // Create and sign the request. $url = sprintf('https://spreadsheets.google.com/feeds/list/%s/%s/private/full', urlencode(get_option('araa_spreadsheet_id')), urlencode(get_option('araa_worksheet_id'))); $request = new Google_Http_Request($url, 'POST'); $request->setRequestHeaders(array('GData-Version' => '3.0', 'Content-Type' => 'application/atom+xml')); $request->setPostBody($body); try { $response = $client->getAuth()->authenticatedRequest($request); } catch (Google_Auth_Exception $e) { return new WP_Error('sheets', 'Could not open the members spreadsheet for writing'); } if ($response->getResponseHttpCode() != 201) { return new WP_Error('sheets', 'Could not write your details to the member spreadsheet'); } // Send an email to the admin with the details. araa_registration_send_emails($data); return new WP_Error(); }
private static function _create_contact($client, $cid, $id, $name, $emailAddress, $phoneNumber, $industryGroup, $address, $comments, $company, $title, $birthday, $url, $referral, $manager, $workPhone, $cellPhone, $faxPhone) { $doc = new DOMDocument(); $doc->formatOutput = true; $entry = $doc->createElement('atom:entry'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005'); $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gContact', 'http://schemas.google.com/contact/2008'); $doc->appendChild($entry); if ($id !== false) { $idDom = $doc->createElement('id', $id); $entry->appendChild($idDom); } $categoryDom = $doc->createElement('category'); $categoryDom->setAttribute('term', 'user-tag'); $categoryDom->setAttribute('label', $industryGroup['title']); $entry->appendChild($categoryDom); $titleDom = $doc->createElement('title', $name); $entry->appendChild($titleDom); $contentDom = $doc->createElement('content', $comments); $entry->appendChild($contentDom); $emailDom = $doc->createElement('gd:email'); $emailDom->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); $emailDom->setAttribute('address', $emailAddress); $entry->appendChild($emailDom); if (!empty($phoneNumber)) { $phoneNumberDom = $doc->createElement('gd:phoneNumber', $phoneNumber); $phoneNumberDom->setAttribute('rel', 'http://schemas.google.com/g/2005#main'); $phoneNumberDom->setAttribute('primary', 'true'); $entry->appendChild($phoneNumberDom); } if (!empty($workPhone)) { $phoneNumberDom = $doc->createElement('gd:phoneNumber', $workPhone); $phoneNumberDom->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); $entry->appendChild($phoneNumberDom); } if (!empty($cellPhone)) { $phoneNumberDom = $doc->createElement('gd:phoneNumber', $cellPhone); $phoneNumberDom->setAttribute('rel', 'http://schemas.google.com/g/2005#mobile'); $entry->appendChild($phoneNumberDom); } if (!empty($faxPhone)) { $phoneNumberDom = $doc->createElement('gd:phoneNumber', $faxPhone); $phoneNumberDom->setAttribute('rel', 'http://schemas.google.com/g/2005#fax'); $entry->appendChild($phoneNumberDom); } if (!empty($address)) { $postalAddressDom = $doc->createElement('gd:postalAddress', $address); $postalAddressDom->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); $postalAddressDom->setAttribute('primary', 'true'); $entry->appendChild($postalAddressDom); } if (!empty($company) || !empty($title)) { $orgDom = $doc->createElement('gd:organization'); $orgDom->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); $orgDom->setAttribute('primary', 'true'); if (isset($company) && !empty($company)) { file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . 'Company: ' . PHP_EOL . var_export($company, true) . PHP_EOL, FILE_APPEND); $orgNameDom = $doc->createElement('gd:orgName', $company); $orgDom->appendChild($orgNameDom); } if (isset($title) && !empty($title)) { file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . 'Title: ' . PHP_EOL . var_export($title, true) . PHP_EOL, FILE_APPEND); $orgTitleDom = $doc->createElement('gd:orgTitle', $title); $orgDom->appendChild($orgTitleDom); } $entry->appendChild($orgDom); } if (!empty($referral)) { $referralDom = $doc->createElement('gd:extendedProperty'); $referralDom->setAttribute('name', 'referral'); $referralDom->setAttribute('value', $referral); $entry->appendChild($referralDom); } if (!empty($manager)) { $managerDom = $doc->createElement('gd:extendedProperty'); $managerDom->setAttribute('name', 'manager'); $managerDom->setAttribute('value', $manager); $entry->appendChild($managerDom); } if (!empty($birthday)) { $birthdayDom = $doc->createElement('gContact:birthday'); $birthdayDom->setAttribute('when', $birthday); $entry->appendChild($birthdayDom); } $birthdayDom = $doc->createElement('gContact:relation'); $birthdayDom->setAttribute('label', 'Ontraport Contact'); $entry->appendChild($birthdayDom); if (!empty($url)) { $websiteDom = $doc->createElement('gContact:website'); $websiteDom->setAttribute('href', $url); $websiteDom->setAttribute('rel', 'http://schemas.google.com/g/2005#profile'); $websiteDom->setAttribute('primary', 'true'); $entry->appendChild($websiteDom); } $groupMemDom = $doc->createElement('gContact:groupMembershipInfo'); $groupMemDom->setAttribute('href', $industryGroup['id']); $groupMemDom->setAttribute('deleted', 'false'); $entry->appendChild($groupMemDom); $xmlToSend = $doc->saveXML(); file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . 'Request XML' . PHP_EOL . $xmlToSend . PHP_EOL, FILE_APPEND); if ($cid !== false) { file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . '%%%% Priming UPDATE request header with CID: ' . $cid, FILE_APPEND); $req = new Google_Http_Request('https://www.google.com/m8/feeds/contacts/default/full/' . $cid); $req->setRequestHeaders(array('content-type' => 'application/atom+xml; charset=UTF-8; type=feed')); $req->setRequestMethod('PUT'); $req->setPostBody($xmlToSend); } else { file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . '++++ Priming CREATE request header', FILE_APPEND); $req = new Google_Http_Request('https://www.google.com/m8/feeds/contacts/default/full'); $req->setRequestHeaders(array('content-type' => 'application/atom+xml; charset=UTF-8; type=feed')); $req->setRequestMethod('POST'); $req->setPostBody($xmlToSend); } file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . 'Making request', FILE_APPEND); $val = $client->getAuth()->authenticatedRequest($req); $response = $val->getResponseBody(); file_put_contents(dirname(__FILE__) . '/update.txt', PHP_EOL . PHP_EOL . '===RESPONSE===' . PHP_EOL . $response . PHP_EOL . PHP_EOL, FILE_APPEND); $xmlContact = simplexml_load_string($response); $xmlContact->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005'); return OPContactProxy::xml2array($xmlContact); }