How to detect if Google account hasn't Gmail - gmail-api

How can I recognize Google accounts without Gmail?
I use OAuth2 for authorization and then download user messages.
But if Google account hasn't Gmail, then I receive the error while getting data from api:
{
"errors": [
{
"domain": "global",
"reason": "failedPrecondition",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
What is the best way to detect accounts without Gmail?
Now I just send test GET request to gmail-api and check that it returns OK.
But I'm looking for best solution.

Related

google cloud mailer api 429 error Resource has been exhausted (e.g. check quota)

i get the below error randomly when using the google mailer api to send emails using the wordpress post smtp plugin, i can replicate the email if i send 200 bulk emails, but checking the peak it doesnt get near the peak, any failed emails i have to re-send
{
"error": {
"code": 429,
"message": "Resource has been exhausted (e.g. check quota).",
"errors": [
{
"message": "Resource has been exhausted (e.g. check quota).",
"domain": "global",
"reason": "rateLimitExceeded"
}
],
"status": "RESOURCE_EXHAUSTED"
}
}
rateLimitExceeded is flood protection your going to fast slow your code down.

How can i use Gmail API to send an email as per the

I need help on to Read Unreaden emails count / send an email to specific or group of people and search with senders id or date to find a specific email using API Only, no programming I did the action like this https://www.googleapis.com/gmail/v1/users/gmailid#gmail/profile on the browser and i got the output like below
{
"error": {
"errors": [{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}],
"code": 401,
"message": "Login Required"
}
}
I know, i have to pass oAuth token or client id and client secreat to the url, but i dont know how can i pass that info through URL.
Also i tried in Post-Man and i could not able tocreate the oAuth token, it is asking call back and redirect url that i dno know.
Can some body give me the idea pleaseI need only API Solution, because i need to work on API stuff, i can successfully implemented the same using java. But i could not able to do this using API ( Am not using any programming to handle the API, only Browser calls and most likely Post-Man only)
You only need the access token to do the HTTP request. In this case, the syntax to get the Gmail profile would be this:
https://www.googleapis.com/gmail/v1/users/USERID/profile?access_token=ACCES_TOKEN
You can easily request the tokens (and do HTTP requests) in the OAuth 2.0 Playground. You can also read more about the getProfile request of the Gmail API here.
EDIT:
To get the number of unread messages, you have to use the q parameter, and change your request to messages:
https://www.googleapis.com/gmail/v1/users/me/messages?q=is:unread&access_token=ACCESS_TOKEN

Error 403, Metadata scope doesn't allow format FULL . Web application Gmail API get message through postman

I'm getting forbidden 403 error when hitting Gmail API get message through postman please help me how to solve this. error
https://www.googleapis.com/gmail/v1/users/userId/messages
this url for getting message list
https://www.googleapis.com/gmail/v1/users/userId/messages/id
this is for getting message for particular id
I can able to hit the get message list API but get Message API not working for me
I'M doing all these stuff through postman
error message :
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Metadata scope doesn't allow format FULL"
}
],
"code": 403,
"message": "Metadata scope doesn't allow format FULL"
}
}
This is another disappointing design in the Gmail API. I resolved this issue with the following steps:
Remove GmailScopes.GMAIL_METADATA from scopes setup.
Remove the credential file from your local FileSystem. This file is generated by Google's Authorization Flow which store your credential locally.
Re authorize your app by signing in again https://accounts.google.com/o/oauth2/auth?access_type=offline....
Hope this helps you guys out.

Google Drive upload file rest api returns 401 error

I want to store my json object to google drive.
And google authentication is working fine.
But when I am calling google drive api, it returns 401 error.
I set authentication, content-type, and content-length to api headers.
Not sure why this happen.
401: Invalid Credentials
Invalid authorization header. The access token you're using is either expired or invalid.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization",
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Suggested action: Refresh the access token using the long-lived refresh token. If this fails, direct the user through the OAuth flow, as described in Authorizing Your App with Google Drive.

Gmail SendAs Settings for Delegated Accounts

I'm trying to get the signature for a delegated account using the new User.settings capabilities in the Gmail API.
https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs/get
I have two accounts in the same Apps org but with different domain names. In the Gmail UI, I log in via my "primary" account and in the accounts list I see the "secondary" account with "(delegated)" appearing after the email address.
However, if I try and do this:
GET https://www.googleapis.com/gmail/v1/users/secondary%40domainB.com/settings/sendAs/secondary%40domainB.com?key={MY_API_KEY}
I get this 403 error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Delegation denied for primary#domainA.com"
}
],
"code": 403,
"message": "Delegation denied for primary#domainA.com"
}
}
Is this not supported or am I taking the wrong approach?
did you gave the domain wide delegation to your service account?
The Gmail API does not currently support access by delegates (see this answer). You need to either use 3LO credentials or service account credentials with domain-wide delegation.

Resources