I feel like I\'m missing something stupid...
I\'m using the PHP SDK for the new Gmail API to fetch an attachment from an email. I can get the attachment content, but un
There may be an issue with decoding the attachment data. Try using this string replace on the attachment data before writing it to a file.
$data = $g->gmail->users_messages_attachments->get($email_account, $email_message_id, $p->getBody()->getAttachmentId());
// Converting to standard RFC 4648 base64-encoding
// see http://en.wikipedia.org/wiki/Base64#Implementations_and_history
$data = strtr($data, array('-' => '+', '_' => '/'));
$fh = fopen(DOC_ROOT."/file.pdf", "w+");
fwrite($fh, base64_decode($data->data));
fclose($fh);