Clear Android GMail search history programmatically - search

I'm trying to clear the GMail search history, but it's not working. How should I approach this?
SearchRecentSuggestions xxx =
new SearchRecentSuggestions(getBaseContext(), "com.google.android.gm.SearchHistoryProvider", 1);
xxx.clearHistory();

Related

Gmail IMAP Javamail search returns no messages where web does

I'm working on load testing a web application that sends links via email. I have a gmail account set up specifically to be the recipient for this. When generating new accounts I add a guid to the recipient email (eg. loadtest_nmndbiwpdi#gmaildomain.com). When I execute the test it will either succeed entirely or fail entirely, but failures seem to be pretty random.
Here is my search snippet:
if (!inbox.isOpen()) {
inbox.open(Folder.READ_ONLY);
}
SearchTerm toTerm = new RecipientTerm(RecipientType.TO, new InternetAddress(to));
messages = inbox.search(toTerm);
While the script is running, it executes this in a 100 iteration loop with a 3 second pause. When it's failing script output with imap debugging on repeatedly shows the following:
A4 SEARCH TO loadtest_nmndbiwpdi#gmaildomain.com ALL
* SEARCH
A4 OK SEARCH completed (Success)
But no actual result. during the period of execution, however, I can do a search in gmail for this recipient and it pops right up. Any suggestions for getting to the bottom of this?
Gmail doesn't exactly implement the IMAP spec, especially for searching. Gmail searches are always for whole words, although that shouldn't be a problem here.
You can try using the Gmail-specific support in JavaMail, e.g., the GmailRawSearchTerm class.
I implemented a local cache. I initialize it at the beginning of the load test scenario, downloading the last days messages and capturing the last messages UID (using gmail imap plugin). Any time a session looks for an email it looks in the local cache. If it's not there it sets a flag so other sessions don't overlap caching and retrieves the newest messages.
Because it was intermittent, I wanted to give it a few days. It's run perfectly for the past 4 days. I could probably go one step better and set up a listener on the folder for new mail, but for now I'm satisfied that gmail was just returning 'success' but not doing the search after so many imap searches in succession.
Thanks to all for your feedback and suggestions!

How does a Gmail message Id or ThreadId map to the new Gmail UI?

Edit: addressing the first comment below and for clarity, this isn't a code question. The question is simply:
What do I put into the URI querystring of the new Gmail UI to view a draft message created by the Gmail API?
Despite this not really being a code question, I'm asking on Stack Overflow as it's Google's preferred platform for Gmail API questions.
--
If I view a draft message in the new Gmail UI, the URI is something like this:
https://mail.google.com/mail/u/1/?zx=iij9apqgzdf4#drafts?compose=jrjtXSqXwlFGnSGCQgDCdnHGVFdlpFMgzsCNgpQstQLxdLCMkjKstBmWZkCmjhWTQnpsZCJF
I can't see any way to create such a link from the Id or ThreadId of a message created via the Gmail API.
Previously, one could do this:
https://mail.google.com/mail/u/1/?zx=ov61dxfbrcga#drafts?compose=1631caae9dbb074d
where the value of "compose" is the Id.
How can the same thing be accomplished in the new UI?
I've been encountering the same problem and have had some success in this problem, as well as some issues I still can't get past.
Good news: The new compose parameter format is some kind of "base40" encoding. I searched the Gmail source for a restricted alphabet string, and found and deobfuscated the bit of code doing this encoding/decoding: https://gist.github.com/danrouse/52212f0de2fbfe33cfc56583f20ccb74
This code includes an encode and decode function which should work for Gmail-format query parameters.
Bad news: The values that it is encoding to open draft emails do not appear to be available using the Gmail API. Specifically, they look like this:
thread-f:NEW_THREAD_ID+msg-a:DRAFT_ID -- while the draft ID is the same as it was before, the Thread ID does not appear to match any of the IDs that the Gmail API returns.
Interestingly, if you inspect the subject row in the Gmail UI, it has dataset attributes including all of both the old format and new format IDs - but it's still unclear how to get the new ones programatically.
Thanks to #frank-szilinski - he pointed out that the old format is now translated. I.e. this now works again:
https://mail.google.com/mail/ca/u/1/#drafts/1661237c4db71ace
It doesn't seem to work when the Gmail tab isn't already open, however.
Building on #kremonte gist, and #chris-wood comments, I made a rails gem that correctly creates the open-the-draft-inside-gmail URL.
It's here - https://github.com/GoodMeasuresLLC/gmail_compose_encoder
It's for the use case of "my code created a draft (prepopulated with some text, of course) and now I want to open the draft in compose mode so that my user can review it before hitting "send".
How to get the URL for a draft
If, for example you use a list request from which you get your draft objects:
{
"id": string,
"message": {
object (Message)
}
}
You can take this id and put it into a URL in this format:
mail.google.com/mail/#inbox?compose=[id]
Eg.
mail.google.com/mail/#inbox?compose=3doinm3d08932d
This will open up GMail with the relevant draft open.
I was struggling because I wanted it to work with multiple accounts. However the authuser parameter did not help.
Inserting the email address instead of the integer after the u/ component solved the problem.
https://mail.google.com/mail/u/{email_address}/#drafts?compose={message_id}
The message id is the one provided by the API.

gmail-api to check how many mails are unread and user has not replied to

I am developing an android app based on gmail-api in which I need to show how many mails are unread (based on a particular sender/subject) , and also need to show how many mails the user has not replied to (based on a particular sender/subject) . If anybody has done this pls let me know if this is feasible.
You need to use Users.messages: list method since it only return messages that match the specified query. It supports the same query format as the Gmail search box. For example, from:someuser#example.com rfc822msgid: is:unread.
Based also from this related SO ticket, the q parameter (query) can be all kinds of stuff and it is the same as the gmail search bar on the top of the web interface. You can use this search method to find unread messages, for example like
List<Message> unreadMessageIDs = ListMessages(service, "me", "is:unread");.
Hope this helps! :)

Extract Instagram Follower/Following Data

I wanted to extract Instagram Follower/Following Data(other user, not my own) and also the names/userid of the Follower/Following. I have searched through the forum but so far what I found is that need authentication before could access any basic data from the Instagram user.
May I know is it possible not to go through the authentication but still able to pull the relationship data (following/follower) data?
What I am trying to achieve here is to track for example do a data analysis of how many followers does a particular public profile of a instagram user has (i.e. maybe some newly opened toy shop that has started a instagram profile). Authenticating each and every single shops that have started a public instagram profile is not feasible. Hence, would there be a way to extract that data using going through the authentication process as described by the API?
Thanks.
My answer is that you need need authentication with some IG account first. After that, the information is all available as long as the account you are looking at is 'public'
API doesn't provide the list of follower anymore even if you are authentificate
You need to do some other technique like the web scraping one (parse the code of the HTML )
This is seriously not my area and the question I was answering to has been closed.
I have spent so long trying to figure this out and although it is a very different solution it's probably going to work for longer.
Open your browser in Mobile mode (no idea how to do).
I have used a python script which did this for me but I will update it with help from the comments
Open a New Tab, acess the profile you want to explore and press followers/following respectively.
Looking at the list of followers/folowing
Inspect any element and go to 'Console' at the top
On the console, paste this and hit Enter.
const arrHtml = document.getElementsByClassName('_ab8w _ab94 _ab99 _ab9f _ab9m _ab9p _abb- _abcm');
while (!!arrHtml.length) {
arrHtml[0].parentNode.removeChild(arrHtml[0])
}
And this
const arrHtml = document.getElementsByClassName('_ab8w _ab94 _ab99 _ab9f _ab9m _ab9p _abbj _abcm');
while (!!arrHtml.length) {
arrHtml[0].parentNode.removeChild(arrHtml[0])
}
And this
const arrHtml = document.getElementsByClassName('_ab8y _ab94 _ab99 _ab9f _ab9m _ab9p _aba_ _abcm');
while (!!arrHtml.length) {
arrHtml[0].parentNode.removeChild(arrHtml[0])
}
And this
const arrHtml = document.getElementsByClassName('_ab8w _ab94 _ab97 _ab9h _ab9k _ab9p _abb0 _abcm');
while (!!arrHtml.length) {
arrHtml[0].parentNode.removeChild(arrHtml[0])
}
Now that everything has been stripped away, except for the usernames.
Click anywhere and use Ctrl + A
Copy (Ctrl + C)
And paste (Ctrl + V) wherever you like. enjoy'

autocomplete search field for blackberry

I want to implement the an auto complete feature in an app am currently developing. I would have used the Blackberry native auto-complete field but I want the auto complete list to be gotten from a web server. This feature is being implemented in the search screen of google maps for blackberry.
Please can u give ideas on how to go about this?
I didn't try but I don't see any issue to do that.
You need to add listener for the EditField - getEditField will help you.
After getting list of suggestions, you pack them to BasicFilteredList and set it to AutoCompleteField with setFilteredList.
You should think also about implementation of case when network is not reachable.
Great example from http://devblog.blackberry.com/2010/04/how-to-use-autocompletefield/
After getting your data back from the web server, store the searchable data as String[].
Then you just need the following code to make your AutoCompleteField work:
BasicFilteredList filterList = new BasicFilteredList();
//my query to sqlite database, yours could just be parsed from your webserver or whatever
String[] list = db.getSearchSuggestions(totalCount);
filterList.addDataSet(1, list, "list", BasicFilteredList.COMPARISON_IGNORE_CASE);
final AutoCompleteField autoComplete = new AutoCompleteField(filterList);

Resources