0
votes

Ok so i am using Pub/Sub subscrition and using Push into an endpoint URL to read email from gmail.

It works perfect for short emails but once and email is over mayber200 characters it only reads first 100 or so characters.

Here is the screen shot on my google api console

enter image description here

and here is the code in the receiver file

$ch = curl_init('https://www.googleapis.com/gmail/v1/users/me/messages?labelIds=Label_56&maxResults=5');

    curl_setopt_array($ch, array(
        CURLOPT_POST => false,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_HTTPHEADER => array(
            'Authorization: Bearer '. $tokenval,
             'Content-Type: application/json', 
        ),
    ));

    // execute request and get response
   $result = curl_exec($ch);


   $allmessages = json_decode($result);
   $allmessage = $allmessages->messages; 


   for($i=0;$i<count( $allmessage);$i++)
   {
     $checkoldmsgid =  $this->Customer_m->getCount('messages',array('massageid'=>$allmessage[$i]->id ));

     if( $checkoldmsgid ==0)
     {
         $ch = curl_init('https://www.googleapis.com/gmail/v1/users/me/messages/'.$allmessage[$i]->id);

                curl_setopt_array($ch, array(
                    CURLOPT_POST => false,
                    CURLOPT_RETURNTRANSFER => TRUE,
                    CURLOPT_HTTPHEADER => array(
                        'Authorization: Bearer '. $tokenval,
                         'Content-Type: application/json'
                    ),
                ));

             // execute request and get response
            $resultm = curl_exec($ch);
            $msgval = json_decode($resultm);

            $sendernum =explode('@',$msgval->payload->headers[19]->value);
            $recivernum =explode('@',$msgval->payload->headers[0]->value);
            $createdat =   date('Y-m-d H:i:s',strtotime($msgval->payload->headers[18]->value));

Is there a line of code that i need to enter to read full emails?

1

1 Answers

1
votes

According to the documentation, you can pass an optional parameter for the format:

Acceptable values are:

"full": Returns the full email message data with body content parsed in the payload field; the raw field is not used. (default)

"metadata": Returns only email message ID, labels, and email headers.

"minimal": Returns only email message ID and labels; does not return the email headers, body, or payload.

"raw": Returns the full email message data with body content in the raw field as a base64url encoded string; the payload field is not used.

Try changing your endpoint to include the format parameter:

$id = $allmessage[$i]->id;
$endpoint = "https://www.googleapis.com/gmail/v1/users/me/messages/$id?format=full";
$ch = curl_init($endpoint);