Get all gmail threads with google script - scripting

In Google scripts I can get inbox threads by
GmailApp.getInboxThreads(0,100);
but how can I get all threads, last 100, not just in the inbox. Or better yet all threads created yesterday.
Thank you

How about this answer? I think that you can achieve what you want to do using Gmail API. When you use these sample scripts, please enable Gmail API at Advanced Google Services and API console.
Preparation for using sample scripts
Enable Gmail API v1 at Advanced Google Services
On script editor
Resources -> Advanced Google Services
Turn on Gmail API v1
Enable Gmail API at API console
On script editor
Resources -> Cloud Platform project
View API console
At Getting started, click Enable APIs and get credentials like keys.
At left side, click Library.
At Search for APIs & services, input "Gmail". And click Gmail API.
Click Enable button.
If API has already been enabled, please don't turn off.
If now you are opening the script editor with the script for using Gmail API, you can enable Gmail API for the project by accessing this URL https://console.cloud.google.com/apis/api/gmail.googleapis.com/overview
Sample scripts
1. Retrieve 100 threads
var result = Gmail.Users.Threads.list("me", {maxResults:100});
2. Retrieve all threads created before 1 day.
var result = Gmail.Users.Threads.list("me", {q: "newer_than:1d"});
References :
Advanced Google Services
Gmail API
Search operators you can use with Gmail
If this was not useful for you, I'm sorry.

Related

How can I create OAuth based login with Open AI api?

I'm trying to build an app using GPT3 APIs and would like users to login to the app using OpenAI's credentials so as to use their account for GPT3 APIs requests, however there is no support for 3rd party login so far in Open AI's documentation. Anyone has ideas on how this can be done?
As far as I'm concerned Open ai does not have an oauth API like Google (for example). The only idea that occurs to me is to ask the user for their Open ai Api key and make the requests through that key

whatsapp cloud api enable whatsapp_business_messaging permission

i have been trying to send whatsapp messages using cloud api, but its expecting to enable whatsapp_business_messaging permission which is by default disabled when associating with any app that has been created.
https://developers.facebook.com/docs/whatsapp/cloud-api/get-started#get-access-token.
i didn't find any documentation pertaining to enable the above mentioned permission. Kindly assist
Edited
WhatsApp cloud API is Now Public!
According to their docs,
To start using it for development prepose
Register as a Meta Developer
Enable two-factor authentication for your account
Create a Meta App: Go to developers.facebook.com > My Apps >
Create App. Select the "Business" type and follow the prompts on
your screen.
From the App Dashboard, click on the app you would like to connect
to WhatsApp. Scroll down to find the "WhatsApp" product and click
Set up.
the onboarding process performs the following actions:
our App is associated with the Business Manager that you chose
A WhatsApp test phone number is added to your business. You can use this test phone number to explore the WhatsApp Business Platform
without registering or migrating a real phone number.
for more info please refer to whatsapp cloud getting started docs
Yes, WhatsApp Cloud API is now public.
With the Cloud API, businesses can directly get access to WhatsApp Business API from Facebook, in minutes.
For more info check out this WhatsApp Cloud API Guide.
I recently made an open-source python wrapper for newly WhatsApp Cloud API to help developers easily get started, You really wanna have a look at it https://github.com/neurotech-HQ/heyoo.
Installation
pip install --upgrade heyoo
Here is the sample code to send a message ;
>>> from heyoo import WhatsApp
>>> messenger = WhatsApp('TOKEN', phone_number_id='104xxxxxx')
>>> messenger.send_template('hello_world', 'your number')
For Javascript developers please have a look into Heyhooh
Installation
npm install heyooh
Here how sending to send messages;
import WhatsApp from heyhooh
let messenger = new WhatsApp('TOKEN', phone_number_id='104xxxxxx')
messenger.send_template("hello_world", "255757xxxxxx")
For PHP Developers whatsappcloud-php
Installation
composer require zepson/whatsappcloud-php
Here how the code to send a message;
<?php
require_once 'vendor/autoload.php';
use zepson\Whatsapp\WhatsappClass;
$token = 'YOUR_META_WHATSAPP_APP_ACCESS_TOKEN';
$phone_number_id = '10726082513218961';
//send message
$tsap = new WhatsappClass( $phone_number_id, $token);
$sendtsap = $tsap->send_template('hello_world', '255654485755');
print_r($sendtsap);

What is the URL for interacting with the Google API Interactive Console to test out queries and get JSON results?

I am trying to find something from Google Cloud that is similar to the Interactive Spotify API Web Console. Does anyone have any ideas that requires a sign into the Google account associated with the Google Cloud? Thanks!
This is available through the API reference pages: https://cloud.google.com/sql/docs/apis
On every method page, there's a form you can use on the right to test it out from the browser using your Google account.
For example, take a look at this page to list your Cloud SQL instances: https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/list

How to display external API Oauth Dialog for Google Sheets AddOn

I'm playing around with building an app to integrate a 3rd party API into google sheets using app script and the new AddOn API's for google docs. I've got the Oauth2.0 flow working by adapting this code here. This works, but I don't want this app to be a standalone web app - I just want to add another menu with a few select functions - one of which will be authenticate to the spreadsheet. I have this working in parts (1. new menu with authenticate button that runs a function when clicked. 2. Url that starts Oauth process when I hit that specific URL in a another window), I just am not sure how to connect them.
My problem is that I'm not sure how to display the 3rd party API's Oauth dialog in a way that is integrated with Google Docs. I've tried loading it into a sidebar, but that doesn't seem to be working. Is there a way to open a 3rd party Oauth2.0 dialog with app script?
This is my first interaction with app script but It'e been pretty easy and painless so far. I'm just wondering what the best way to approach this problem would be.
Thanks!
There is no built-in way to do a 3rd party OAuth2 flow using Google Apps Script. However it is possible to write an OAuth2 flow on top of Apps Script, and this library is one such implementation:
https://github.com/googlesamples/apps-script-oauth2

Gmail Sidebar gadget development, getting started

I'm kind of new to dealing with Gmail API and I have a question regarding the development environment.
I want to create a simple application that fetches unread emails from a gmail user, sends it to a processing server of mine (RESTful web service) where I analyze the data and extract some information, then finally use the extracted information to add it to the user's Google calendar.
I was thinking of developing a sidebar gadget but I was curious about which IDE to use. Do I use the Google scripts API? Will it make my gadget portable? Which IDE to use?
I know about the Gmail API that uses oAuth access to IMAP & SMTP but how can I integrate it with the sidebar gadget? Where do I write the code? Which language?
First, you will want to read Google's Gmail gadget documentation to learn how to make them.
Basically, you can either use the Google Gadget Editor (GGE), which is a very simple IDE that runs in your browser, or you can use whatever editor you prefer for editing JavaScript and XML. You will also need a website where you can post your code. A google gadget is an XML+Javascript file that resides in some webserver and that follows the schema google dictates.
Google Apps Scripts are a different thing. They are scripts that run in a google spreadsheet and can access the user's google services (docs, gmail, and some other ones). But, they are not Gadgets. To write one, create a new spreadsheet then go to Tools->script editor.
IMAP and SMTP are another thing. They are protocols for talking to a mail server. There are imap and smtp libraries available for nearly all programming languages. But, that is not what you want if you want to implement a gadget.
One important thing to consider is that Apps Script is the only way to get full access to Gmail. You could easily automate all the processing to send the information to Calendar.