1

hi im trying to get a list of my email using gmail api with php but i got error 400, is PHP for Gmail API is still developed or just im doin it wrong ?

$optParams = [];
    $optParams['maxResults'] = 5; // Return Only 5 Messages
    $optParams['labelIds'] = 'INBOX'; // Only show messages in Inbox
    $optParams['q'] = 'from: "abc"'; // Only show messages in Inbox
    $list = $gmail->users_messages->listUsersMessages("my email",$optParams);

btw i'm non g suite and using service account Thanks

--- update ---

Here's my $gmail variable source

 putenv('GOOGLE_APPLICATION_CREDENTIALS='.base_path('service_account.json'));
   $client->useApplicationDefaultCredentials();
    $client->setScopes(\Google_Service_Gmail::MAIL_GOOGLE_COM);
    $client->setAccessType('offline');        // offline access
    $client->setIncludeGrantedScopes(true);   // incremental auth
    $gmail = new \Google_Service_Gmail($client);
protrafree
  • 96
  • 10
  • Gmail api is working fine (I checked before commenting here). Are you sure you have the correct authorization ? with the right scopes ? Try removing `q` parameter (in the case where the filter is not written the way it should). How do you create your `$gmail` service ? Are you trying to access your own account emails, or is it somebody's emails ? In that latter case, it should have been authorized with the appropriate process – Pierre Feb 27 '18 at 09:39
  • You're doing it wrong. possible duplicate of https://stackoverflow.com/questions/32591549/gmail-api-400-bad-request-when-trying-to-send-an-email-php-code – ReyAnthonyRenacia Feb 27 '18 at 10:02
  • @ pierre im update my answer above – protrafree Feb 27 '18 at 14:26
  • @noogui okay im gonna check it – protrafree Feb 27 '18 at 14:27

0 Answers0