I have headless software in Jetson Xavier. I am using Gmail API for sending mail. My code is working correctly in Laptop however GUI service is disabled in Jetson, browser cannot be opened. So, Authentication is failed when I try to use Gmail API in Jetson.
I have copied authenticated "token.pickle" to Jetson from laptop. It works fine that for a short time. Then, it wants an authentication again.
How can I solve this issue? How to block the browser to be opened for authentication in Jetson?
Thanks.
This part of code is for authentication:
class EmailSender:
def __init__(self):
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/gmail.compose']
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
creds_dir = os.path.dirname(os.path.abspath(__file__)) + '/credentials.json'
flow = InstalledAppFlow.from_client_secrets_file(
creds_dir, SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
self.service = build('gmail', 'v1', credentials=creds)