Specifying which Google account to use when executing a Google Apps Script webapp request - gmail

I have a browser extension which is scraping the threadId from the URL when the user is reading an email in Gmail, and is using this threadId to fetch circumstantial data using the Google Apps Script API.
The extension do however not know which of maybe several Google accounts are reading this message; it knows only the URL to my Apps Script webapp and the threadId. So when it executes the fetch, the webapp will the interpret request as coming from the default user session, which in some cases is wrong and will thus result in an null when executing GmailApp.getThreadById(e.parameter.threadId).
So what I am wondering is whether it is possible to specify what Google account to use when querying the webapp. Are there any possibilities other than asking the user to log off all other accounts and set the current one as default?

Unfortunately Google Apps Script does not have good support for multiple logins. See this page for more information.

You can add an authuser parameters to the requests you make to your the Google Apps script.
The authuser param's values are zero based indexes for all the Google accounts that are logged in the current browser session.
Now for extracting what index value you need to send, you can scrape the current page for profiles.google.com links that have authuser param and extract your value from them and send it with your requests.
The link might look like this:
https://profiles.google.com/ ... authuser=0
Specifically for gmail, the url also contains the current authuser index, For example:
https://mail.google.com/mail/u/1/#inbox
This URL above contains the authuser value 1 at the end (before the fragment and after /u/)
I know this is very complex and is looks more like a hack. But I think this surely is a workaround, until Google provides a better way to specifying the context for your apps script requests.
I hope this might be helpful.
Thanks.

Related

Scraping linked-in profile to get user email using NodeJS Puppeteer and scrapedin

Dears, I'm now working on a project that requires me to scrape the public linked-in profiles to get some info like email, name, company, title, photo (some basic information)
I write it with NodeJS, using Puppeteer and library called scrapedin
This library requires me to log in to LinkedIn with e-mail and password, I created a dummy linked-in account to use it for this library, it worked fine in localhost, but once I uploaded it to the server I should use cookies to login
and here is the problem, after maybe 30 min linked-in restricted the account and I can't use it anymore!
How could I solve this problem
Is there another library for linked-in scraping I can use?
Thank you.
LinkedIn likely restricted your account because they don't want bot activity on their website. You could try to make your script act more human, for example by inserting random wait times between actions using setTimeout(). It could also help to spend some time creating a new human-like dummy account that is less easy to detect as a bot, for example by uploading a profile picture and writing some text.
You could also make the script do some human actions like pressing random like buttons between the scrape actions.

How to implement logic based on external redirects?

I'm building a website for a client (real estate), and on the website are links to a different website (adverts for properties). My client routinely activates and deactivates these adverts when he rents out a certain property.
The hrefs on my links look something like this:
<a href="https://domain.xx/estate/idxx/des-crip-tion-xx-xx-x-xx/">. If the advert is indeed active, it just takes them to the advert. If it is not active, however, the website in question redirects the user to https://domain.xx/estate-for-rent/city/, effectively sending the users to my client's competition.
I wish to implement some logic where, before handing the users over to the other website, the server checks to see if it is redirected to https://domain.xx/estate-for-rent/city/, or some similar logic, and if so, uses preventDefault, or something, and notifies the user that the advert is not available instead of sending them to the other website.
I wonder if I can use the fact that only if the advert is active does the resulting url in the users browser window (after they've been directed to the other website) match the url in my href. Can i somehow get the server to try to access the url in my href, and have it see where it gets redirected, and then do something based on that? On the back-end, I'm running NodeJS with Express by the way, and if it matters, I'm relying heavily on EJS for templating. Thanks in advance for any help!
This sounds more like a problem you could solve on the client as opposed to the server. For example, at a high level here's how I would do it:
Handle the click event for each link (really simple to do a catch-all with jQuery)
Fire off a HEAD request via AJAX to the destination URL (this would be much more efficient than a GET but depends on the external service supporting this verb)
Use the status code to determine what to do next (e.g. 2xx allow redirect, 3xx pop a message and block)

How to track last login date for IBM Domino web user?

Does IBM Domino track the last login date for web users(UserName/Password and internet certificate)? I know the access logs contains this information but wanted to know if there may be something built into Domino (maybe in Address Book). Trying to come up with a method to disable web accounts that have not accessed a domino server in a specified time period.
Thanks,
Kev
The User Activity area in the Database Properties picks up from the log.nsf, which is where this information is stored. But, typically, the log.nsf will only have a few days' worth of information. When I've had this requirement before, I've manually captured it via a custom login page or an initUser function I've had in applications.
One of the easiest solutions is to trigger an action from a live web page that generates a database.nsf?openagent event.
like:
or
Ideally you've use the openagent to print a content type and a response, but if you don't browsers do pretty well with invalid responses from servers.
inside your "myagent" you will have the users name available to you to write it to a document.
Your next challenge will be in getting the agent to trigger, but, not too often, ideally only on login.
When a user uses a custom login form it submits the username/password and redirection url in POST method. You could change that to ...?openagent&nexturl=/blablabla.nsf
Your tiny little agent would run one and only one time upon login and update a document in a your custom logging database.
That's a developer's solution.
There are also admin solutions. The server does keep track of active web sessions, but, it does not drop them into the log.nsf like it does upon session ending for a notes session. I don't think it would be too much work from an admin standpoint to get that information there are a lot of event triggers available to you. It's just been way too long since I worked on any server that anyone cared about statistics.

Enable user to send text to specific Gmail contacts

In our website, we need to achieve a seemingly simple task: Enable the user to send a specific text to all or some of his/her Gmail contacts (including contact selection).
We don't actually need the contact data itself. We prefer some kind of "Gmail Plugin" (if there is one) that asks the user to login and does all the work. Alas, we couldn't find any.
We did find several different Google APIs related to this task. Some of them seem to give us contacts data. Others seem to handle sending email:
There is "Contacts API" under
https://developers.google.com/google-apps/contacts/v3/...
There is "Contacts Service" under
https://developers.google.com/apps-script/reference/contacts/...
There is "Gmail Service" under
https://developers.google.com/apps-script/reference/gmail/...
There is "Gmail Platform Integration" under
https://developers.google.com/gmail/...
Each of the above looks different and there seems to be much overlapping between them.
So what is the recommended method to achieve our original task? Is there a plugin that does it all? If not - should we use separate APIs for getting the contacts data and sending the emails, or are there Google APIs that combine both sub-tasks? In case those are separate tasks - is it possible to email via Gmail, or are there other recommended services for the email sending part?
To directly answer your question: you must use the first API you pointed, Contacts API under https://developers.google.com/google-apps/contacts/v3/.
Basically, you want to use the Google Contacts API with OAuth2 authentication in your website: user will be prompted by Google to allow your website to read user contacts.
First, read a bit about OAuth2 authentication flows here: http://alexbilbie.com/2013/02/a-guide-to-oauth-2-grants/
Second step: register your app on Google Console and get your key/pass for the Contacts API (you'll need contacts.readonly permission): https://console.developers.google.com
Then, as you'll use the OAuth2 for Web Servers, check this Google documentation: https://developers.google.com/accounts/docs/OAuth2WebServer
Alternatively, you can use third part libraries to easily import contacts to your website. There are free libraries, like PHP OpenInviter.org, Ruby OmniAuth gem, and paid alternatives, like CloudSponge.com (multi-language).
Disclaimer: I work for CloudSponge.com.
You could achieve this as you say with Google APIs and a Chrome Extension for example.
The user can add a Chrome Extension from the Chrome Webstore. The Extension will provide the user with a user interface to allow them to compose their message and send to the selected contacts.
The users contacts can be retrieved with the Google Contacts API.
The message can be sent to the selected contacts with the Gmail API.
There is a lot of documentation and examples for all of the above which together will give you what you want.
Depending on how much use this is going to get, you could use a contextual gadget which is browser agnostic - but visible in all emails in Gmail.
This is wrong the idea is to post the text to buffer a and submit pointer to array on buffet a and copy it to class b pointer a 0 than release the array and buffer so new allocation can be done

Recommendation for handling multiple apps in google wallet

I successfully integrated Google Wallet in one app, and now I want integrate it into another. However I can only sent one postback url. Anyone have any approaches to making this work?
Wallet for digital:
Since the postback url is set in your profile, if you must have unique urls, I don't think you can do so without new accounts.
Otherwise, if you can segment based on data (e.g. using the sellerData field), that might be an option...
Hth...

Resources