Saturday, 15 June 2013

Gmail api response headers - getting information contained in angle brackets (php library) -



Gmail api response headers - getting information contained in angle brackets (php library) -

i using gmail api , when seek "from" field specific message, name portion not address. here query works in oauth2 playground:

get https://www.googleapis.com/gmail/v1/users/me/messages/14jj4883c9e195a8?format=metadata&metadataheaders=from&fields=payload%2csizeestimate

it outputs:

{ "payload": { "mimetype": "multipart/mixed", "headers": [ { "name": "from", "value": "first lastly <email@example.org>" } ] }, "sizeestimate": 180758 }

implementing same query in php:

function getmessage($service, $userid, $messageid) { seek { $optparamsget = array(); $optparamsget['format'] = 'metadata'; $optparamsget['metadataheaders'] = 'from'; $optparamsget['fields'] = 'payload,sizeestimate'; $message = $service->users_messages->get($userid, $messageid, $optparamsget); print 'message id: ' . $message->getid() . ' retrieved.<br>'; homecoming $message; } grab (exception $e) { print 'an error occurred: ' . $e->getmessage(); } } $message2 = getmessage($service,$userid,$message_id); if ($message2->getpayload()) { $headers = $message2->getpayload()->getheaders(); foreach ($headers $header) { if ('from' == $header->name) { $name_value = $header->value; echo $name_value . "<br>"; array_push($sendernames,$name_value); echo $header['value']. "<br>"; break; } } } var_dump($headers);

and now, doing var_dump on headers in returned $message not show email address within angle bracket. how this?

the value should there in header. agree phil, think it's "<" , ">" getting hidden/removed since you're printing html output source. :)

php gmail-api

No comments:

Post a Comment