0

I follow the guide at https://developers.google.com/gmail/api/quickstart/php. And the crendentials are generated in this page with readonly permission on gmail.

But the problem is I can get the labels and message id, but when I want to read the content of the message it shows me this.

object(Google_Service_Gmail_Message)#43 (14) {
  ["collection_key":protected]=>
  string(8) "labelIds"
  ["historyId"]=>
  NULL
  ["id"]=>
  NULL
  ["internalDate"]=>
  NULL
  ["labelIds"]=>
  NULL
  ["payloadType":protected]=>
  string(32) "Google_Service_Gmail_MessagePart"
  ["payloadDataType":protected]=>
  string(0) ""
  ["raw"]=>
  NULL
  ["sizeEstimate"]=>
  NULL
  ["snippet"]=>
  NULL
  ["threadId"]=>
  NULL
  ["internal_gapi_mappings":protected]=>
  array(0) {
  }
  ["modelData":protected]=>
  array(3) {
    ["messages"]=>
    array(100) {
      [0]=>
      array(2) {
        ["id"]=>
        string(16) "17388d8760e3206d"
        ["threadId"]=>
        string(16) "17388a5bcacacd5d"
      }
      [1]=>
      array(2) {
        ["id"]=>
        string(16) "17388c325f18148c"
        ["threadId"]=>
        string(16) "17388c3075fbb3de"
      }
      [2]=>
      array(2) {
        ["id"]=>
        string(16) "17388c3075fbb3de"
        ["threadId"]=>
        string(16) "17388c3075fbb3de"
      }
      [3]=>
      array(2) {
        ["id"]=>
        string(16) "17388bf02d3a04a4"
        ["threadId"]=>
        string(16) "17388bf02d3a04a4"
      }
      [4]=>
      array(2) {
        ["id"]=>
        string(16) "17388a5bcacacd5d"
        ["threadId"]=>
        string(16) "17388a5bcacacd5d"
      }
      [5]=>
      array(2) {
        ["id"]=>
        string(16) "17388920e821033a"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [6]=>
      array(2) {
        ["id"]=>
        string(16) "173885252484498b"
        ["threadId"]=>
        string(16) "173885252484498b"
      }
      [7]=>
      array(2) {
        ["id"]=>
        string(16) "17387a3f1d3cec31"
        ["threadId"]=>
        string(16) "17387a3f1d3cec31"
      }
      [8]=>
      array(2) {
        ["id"]=>
        string(16) "17386eec4dd7d110"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [9]=>
      array(2) {
        ["id"]=>
        string(16) "17386eec425e9d07"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [10]=>
      array(2) {
        ["id"]=>
        string(16) "17386eeac65dccf7"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [11]=>
      array(2) {
        ["id"]=>
        string(16) "17386eeabdb30f14"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [12]=>
      array(2) {
        ["id"]=>
        string(16) "17386e333eed7d8f"
        ["threadId"]=>
        string(16) "17386e333eed7d8f"
      }
      [13]=>
      array(2) {
        ["id"]=>
        string(16) "17386b73e5730b1a"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [14]=>
      array(2) {
        ["id"]=>
        string(16) "17386b72d82d2265"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [15]=>
      array(2) {
        ["id"]=>
        string(16) "17386b72d3ced828"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [16]=>
      array(2) {
        ["id"]=>
        string(16) "17386b72c57c966b"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [17]=>
      array(2) {
        ["id"]=>
        string(16) "17386b7281f384c6"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [18]=>
      array(2) {
        ["id"]=>
        string(16) "17386b723de19e8f"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [19]=>
      array(2) {
        ["id"]=>
        string(16) "17386ad85d414e7f"
        ["threadId"]=>
        string(16) "17386ad85d414e7f"
      }
      [20]=>
      array(2) {
        ["id"]=>
        string(16) "1738674915320c0e"
        ["threadId"]=>
        string(16) "1738674915320c0e"
      }
      [21]=>
      array(2) {
        ["id"]=>
        string(16) "17385773e1092a8d"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [22]=>
      array(2) {
        ["id"]=>
        string(16) "173856afc9a3413d"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [23]=>
      array(2) {
        ["id"]=>
        string(16) "17385630dbdd0a72"
        ["threadId"]=>
        string(16) "17385630dbdd0a72"
      }
      [24]=>
      array(2) {
        ["id"]=>
        string(16) "173851aeac5111c5"
        ["threadId"]=>
        string(16) "173851aeac5111c5"
      }
      [25]=>
      array(2) {
        ["id"]=>
        string(16) "17385147136615be"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [26]=>
      array(2) {
        ["id"]=>
        string(16) "17384cc3feee19c3"
        ["threadId"]=>
        string(16) "17384cc3feee19c3"
      }
      [27]=>
      array(2) {
        ["id"]=>
        string(16) "173849aea2aa830a"
        ["threadId"]=>
        string(16) "173849aea2aa830a"
      }
      [28]=>
      array(2) {
        ["id"]=>
        string(16) "17384752b2fa989b"
        ["threadId"]=>
        string(16) "17384261928ca182"
      }
      [29]=>
      array(2) {
        ["id"]=>
        string(16) "173846a2c2cb7579"
        ["threadId"]=>
        string(16) "17382ce180ffea5a"
      }
      [30]=>
      array(2) {
        ["id"]=>
        string(16) "17384628c24c8ff5"
        ["threadId"]=>
        string(16) "17382ce180ffea5a"
      }
      [31]=>
      array(2) {
        ["id"]=>
        string(16) "173846119f0a1fcd"
        ["threadId"]=>
        string(16) "17382ce180ffea5a"
      }
      [32]=>
      array(2) {
        ["id"]=>
        string(16) "1738460ed8525232"
        ["threadId"]=>
        string(16) "1738460ed8525232"
      }
      [33]=>
      array(2) {
        ["id"]=>
        string(16) "173842b56c16717b"
        ["threadId"]=>
        string(16) "173842b56c16717b"
      }
      [34]=>
      array(2) {
        ["id"]=>
        string(16) "1738429d2835919d"
        ["threadId"]=>
        string(16) "17382ce180ffea5a"
      }
      [35]=>
      array(2) {
        ["id"]=>
        string(16) "17384261928ca182"
        ["threadId"]=>
        string(16) "17384261928ca182"
      }
      [36]=>
      array(2) {
        ["id"]=>
        string(16) "1738423a8f6b75bd"
        ["threadId"]=>
        string(16) "17382ce180ffea5a"
      }
      [37]=>
      array(2) {
        ["id"]=>
        string(16) "173840a6d4dcaa76"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [38]=>
      array(2) {
        ["id"]=>
        string(16) "17384073cf1d991f"
        ["threadId"]=>
        string(16) "17384073cf1d991f"
      }
      [39]=>
      array(2) {
        ["id"]=>
        string(16) "17383cad912e5723"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [40]=>
      array(2) {
        ["id"]=>
        string(16) "17383b5d15484553"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [41]=>
      array(2) {
        ["id"]=>
        string(16) "17383b36e39cb556"
        ["threadId"]=>
        string(16) "17383b36e39cb556"
      }
      [42]=>
      array(2) {
        ["id"]=>
        string(16) "17383b36c5b388e3"
        ["threadId"]=>
        string(16) "17383b36c5b388e3"
      }
      [43]=>
      array(2) {
        ["id"]=>
        string(16) "17383a54aab707e8"
        ["threadId"]=>
        string(16) "17383a5301a66726"
      }
      [44]=>
      array(2) {
        ["id"]=>
        string(16) "17383a5301a66726"
        ["threadId"]=>
        string(16) "17383a5301a66726"
      }
      [45]=>
      array(2) {
        ["id"]=>
        string(16) "17383a11cecc0644"
        ["threadId"]=>
        string(16) "17383a11cecc0644"
      }
      [46]=>
      array(2) {
        ["id"]=>
        string(16) "173838e6a5f3a5ae"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [47]=>
      array(2) {
        ["id"]=>
        string(16) "173837bca56a1d19"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [48]=>
      array(2) {
        ["id"]=>
        string(16) "1738342bb9d482d8"
        ["threadId"]=>
        string(16) "17382c0e90cb6a81"
      }
      [49]=>
      array(2) {
        ["id"]=>
        string(16) "17383419227e9a6d"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [50]=>
      array(2) {
        ["id"]=>
        string(16) "173832d7218e494a"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [51]=>
      array(2) {
        ["id"]=>
        string(16) "173832ac4a403c49"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [52]=>
      array(2) {
        ["id"]=>
        string(16) "17383227f2156035"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [53]=>
      array(2) {
        ["id"]=>
        string(16) "1738311229ee11dd"
        ["threadId"]=>
        string(16) "1738311229ee11dd"
      }
      [54]=>
      array(2) {
        ["id"]=>
        string(16) "17382f68ec66f1b4"
        ["threadId"]=>
        string(16) "17382c0e90cb6a81"
      }
      [55]=>
      array(2) {
        ["id"]=>
        string(16) "17382f4cbd854a0b"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [56]=>
      array(2) {
        ["id"]=>
        string(16) "17382e584f45c3f0"
        ["threadId"]=>
        string(16) "17382c0e90cb6a81"
      }
      [57]=>
      array(2) {
        ["id"]=>
        string(16) "17382e0379305cdc"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [58]=>
      array(2) {
        ["id"]=>
        string(16) "17382dfa6e2969b0"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [59]=>
      array(2) {
        ["id"]=>
        string(16) "17382d721b963e6e"
        ["threadId"]=>
        string(16) "17382c0e90cb6a81"
      }
      [60]=>
      array(2) {
        ["id"]=>
        string(16) "17382ce180ffea5a"
        ["threadId"]=>
        string(16) "17382ce180ffea5a"
      }
      [61]=>
      array(2) {
        ["id"]=>
        string(16) "17382cb684a14afb"
        ["threadId"]=>
        string(16) "17382c0e90cb6a81"
      }
      [62]=>
      array(2) {
        ["id"]=>
        string(16) "17382c765cbd2c69"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [63]=>
      array(2) {
        ["id"]=>
        string(16) "17382c25a69193fc"
        ["threadId"]=>
        string(16) "17382c0e90cb6a81"
      }
      [64]=>
      array(2) {
        ["id"]=>
        string(16) "17382b980473afba"
        ["threadId"]=>
        string(16) "17382b980473afba"
      }
      [65]=>
      array(2) {
        ["id"]=>
        string(16) "17382a6053ad623b"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [66]=>
      array(2) {
        ["id"]=>
        string(16) "173829dc05539270"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [67]=>
      array(2) {
        ["id"]=>
        string(16) "17382953d43e6d2e"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [68]=>
      array(2) {
        ["id"]=>
        string(16) "17382951f54400e8"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [69]=>
      array(2) {
        ["id"]=>
        string(16) "1738283dd700be1f"
        ["threadId"]=>
        string(16) "17381f91b7980fa8"
      }
      [70]=>
      array(2) {
        ["id"]=>
        string(16) "17382817e3ef956c"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [71]=>
      array(2) {
        ["id"]=>
        string(16) "17382434bc4401f6"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [72]=>
      array(2) {
        ["id"]=>
        string(16) "17382407155fd5a9"
        ["threadId"]=>
        string(16) "17382407155fd5a9"
      }
      [73]=>
      array(2) {
        ["id"]=>
        string(16) "173822abd1ba0417"
        ["threadId"]=>
        string(16) "173822abd1ba0417"
      }
      [74]=>
      array(2) {
        ["id"]=>
        string(16) "1738229d08afabae"
        ["threadId"]=>
        string(16) "1738229d08afabae"
      }
      [75]=>
      array(2) {
        ["id"]=>
        string(16) "173821fbdba585e3"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [76]=>
      array(2) {
        ["id"]=>
        string(16) "173821f62274c77d"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [77]=>
      array(2) {
        ["id"]=>
        string(16) "173821f4b0b3a0d0"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [78]=>
      array(2) {
        ["id"]=>
        string(16) "17381f94921a2226"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [79]=>
      array(2) {
        ["id"]=>
        string(16) "17381f91b7980fa8"
        ["threadId"]=>
        string(16) "17381f91b7980fa8"
      }
      [80]=>
      array(2) {
        ["id"]=>
        string(16) "17381f692351d2a2"
        ["threadId"]=>
        string(16) "17381f692351d2a2"
      }
      [81]=>
      array(2) {
        ["id"]=>
        string(16) "17381f4cf54262b2"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [82]=>
      array(2) {
        ["id"]=>
        string(16) "17381a0612842c19"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [83]=>
      array(2) {
        ["id"]=>
        string(16) "17381831e849fa05"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [84]=>
      array(2) {
        ["id"]=>
        string(16) "173818301b7cb396"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [85]=>
      array(2) {
        ["id"]=>
        string(16) "1738182ccc9aa350"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [86]=>
      array(2) {
        ["id"]=>
        string(16) "1738182a89d7816d"
        ["threadId"]=>
        string(16) "1738182a89d7816d"
      }
      [87]=>
      array(2) {
        ["id"]=>
        string(16) "1738169b09f8fbeb"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [88]=>
      array(2) {
        ["id"]=>
        string(16) "17381672e8a9a3ad"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [89]=>
      array(2) {
        ["id"]=>
        string(16) "17381672a34dfbd3"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [90]=>
      array(2) {
        ["id"]=>
        string(16) "17381671628b0d95"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [91]=>
      array(2) {
        ["id"]=>
        string(16) "1738166f8362f775"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [92]=>
      array(2) {
        ["id"]=>
        string(16) "1738166abf4d4955"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [93]=>
      array(2) {
        ["id"]=>
        string(16) "173815d7a4281c18"
        ["threadId"]=>
        string(16) "173815d7a4281c18"
      }
      [94]=>
      array(2) {
        ["id"]=>
        string(16) "1738157a9b146603"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [95]=>
      array(2) {
        ["id"]=>
        string(16) "173813a8b52283ff"
        ["threadId"]=>
        string(16) "173813a8b52283ff"
      }
      [96]=>
      array(2) {
        ["id"]=>
        string(16) "17380bb30f2aa99a"
        ["threadId"]=>
        string(16) "17380bb30f2aa99a"
      }
      [97]=>
      array(2) {
        ["id"]=>
        string(16) "173808af8f211145"
        ["threadId"]=>
        string(16) "173808af8f211145"
      }
      [98]=>
      array(2) {
        ["id"]=>
        string(16) "1738040538ea37b5"
        ["threadId"]=>
        string(16) "1737c3dcfcadc3ee"
      }
      [99]=>
      array(2) {
        ["id"]=>
        string(16) "1737fe90d7664ae1"
        ["threadId"]=>
        string(16) "1737fd8eca4a3ce8"
      }
    }
    ["nextPageToken"]=>
    string(20) "17096626277946172238"
    ["resultSizeEstimate"]=>
    int(514)
  }
  ["processed":protected]=>
  array(0) {
  }
}
PHP Notice:  Trying to get property 'mimeType' of non-object in /var/www/poc/read_gmail.php on line 95
PHP Notice:  Trying to get property 'mimeType' of non-object in /var/www/poc/read_gmail.php on line 97
PHP Notice:  Trying to get property 'parts' of non-object in /var/www/poc/read_gmail.php on line 99
PHP Notice:  Undefined index: plain in /var/www/poc/read_gmail.php on line 120

This the result of var_dump of the message object I got from this

$message_id = listMessages($service,$user);

$message = $service->users_messages->get($user, $message_id);
var_dump($message);

I can make request using the message id I got on https://developers.google.com/gmail/api/v1/reference/users/messages/get, so the message id is fine.

I think the problem is about the credential, what can I do for me to read my own email with cli? I am not familiar with googleapi.

When I use google api method

var_dump($message->payload);

what I got is

NULL
  • `I am not familiar with googleapi.` ... hence reading the docs to get familiar. – GetSet Jul 26 '20 at 03:22
  • I have already read the docs, but doc didn't talk about this. – Vincent Hunter Jul 26 '20 at 03:24
  • You have to use their API methods. Looking at the data structure is pointless unless you want to save it somewhere. Hence, you havent really found what you want in their docs yet. Is why should read further. – GetSet Jul 26 '20 at 03:26
  • But when I use its api method getpayload what I got is None, so the problem is that the server returns problematic message body............... – Vincent Hunter Jul 26 '20 at 03:36

0 Answers0