get only new contacts from google contacts api - java

I want to make a query to Google contacts that retrieves all NEW contacts since a given Date.
I am using google contacts api with the following scope: https://www.google.com/m8/feeds/
When I try to make a query that contains publishedMin parameter:
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query myQuery = new Query(feedUrl);
myQuery.setPublishedMin(startDateTime);
myQuery.setMaxResults(1000);
ContactFeed resultFeed = service.getFeed(myQuery, ContactFeed.class);
I get the following error:
com.google.gdata.util.ServiceForbiddenException: Forbidden
This service does not support the 'published-min' parameter.
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:605)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
How else can I get the new contacts since a given date if I cannot use publishedMin.
Is there an alternative or a workaround for this?
I tried using updatedMin and then search every contact for getPublished() to filter them out but all the values are null.
Thanks in advance.

The Google Contacts API does not support a "published-min" parameter. Out of curiosity, where did you find this Java library that is still trying to use it? (if it is the latest version of a Google-provided library then it ought to be updated)
In the mean time, what you are looking for is the updated-min parameter:
https://developers.google.com/google-apps/contacts/v3/#retrieving_contacts_using_query_parameters

Related

Get contacts by phonenumber using gdata-contacts

I am trying to use Contacts query parameters reference. See https://developers.google.com/google-apps/contacts/v3/reference#contacts-query-parameters-reference
I am building the query like this:
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query query = new Query(feedUrl);
query.setMaxResults(1111);
query.setStringCustomParameter("phoneNumber", "123456789");
But Google API is returning all contacts while I just want the contact who has the 123456789 number.
Is it possible to get a google contact by phone number?
thanks
Try changing query to https://www.google.com/m8/feeds/contacts/default/full?q="6785555455" . I tried this in oauth playground and was able to retrieve contact who has matching phone number 6785555455. Here is the response:
<gd:name>
<gd:fullName>Hello</gd:fullName>
<gd:givenName>Hi</gd:givenName>
</gd:name>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#mobile" uri="tel:+91-1234-222-321">(678)-555-5455</gd:phoneNumber>
<gContact:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/guntupalliswathi%40gmail.com/b ase/6"/>
</entry>
</feed>
check this link for reference.

Using regular expression or pattern matching in endpint class for Datastore Google App engine

In my app engine Java application, i want to use RegEx in datastore query to check prefix in one of my fields of DB. I have a column which stores "UserName" . Now i want to implement "Search user" functionality. For that i'll have to use regular expression to which will search users by some particular prefix value.And I referred pattern in Google App engine link.I want to do exactly described in this link. In that they have used Gqlquery with python but i want to implement that in JAVA app engine application. Further i am using this app engine application in my android client. Please any one can help me out to implement Regular Expression` on DataStore. Thank you.
Refering to the Python workaround for "GQL kinda like" queries, the Java implementation with the low level datastore API should look like this :
// From user input
String usernamePrefix = "XX";
Filter usernameGreaterThanPrefixFilter =
new FilterPredicate("username",
FilterOperator.GREATER_THAN_OR_EQUAL,
usernamePrefix);
Filter usernameLessThanLargestPossibleFilter =
new FilterPredicate("username",
FilterOperator.LESS_THAN,
usernamePrefix + "\ufffd");
Filter usernameKindaLikeFilter =
CompositeFilterOperator.and(usernameGreaterThanPrefixFilter, usernameLessThanLargestPossibleFilter);
Query q = new Query("User").setFilter(usernameKindaLikeFilter);
I have never tested this though, if it works I would have learned something thanks to you.
If it does not work, you can always store a fixed length "userPrefix" property on each entity, which would be a substring of the username. You could then query the userPrefix property with a FilterOperator.EQUAL equality filter.

Solr returns same result after adding document with SolrJ

I am trying to get the results from a Solr query, doing a simple /select?q=id:xx
The problem is that its not returning anything when i use solr directly, but when i use SolrJ, like:
SolrQuery query = new SolrQuery();
query.setQuery(queryStr);
query.setRows(10);
QueryResponse rsp = solrServer.getSolrServer().query(query);
It returns the document added with no problem.
How is that possible, i was thinking perhaps the SolrJ its sending an extra parameter internally but i couldnt find it.
I am using Solr 4.2.1
After doing some test i solved the problem, i had to use HttpSolrServer, instead of EmbeddedSolrServer, it seems EmbeddedSolrServer use their own data somehow, so i was managing 2 different datas.
Using HttpSolrServer was the solution.

add filter query in Google app engine

I am having problem with filtering the entities after addFilter() has been
deprecated from Google App Engine .
Objective : to list those Entities which are having UID = "rahul"
what i tried :
com.google.appengine.api.datastore.DatastoreService ds=DatastoreServiceFactory.getDatastoreService();
Query q = new Query("Upload");
q.setFilter(FilterOperator.EQUAL.of("UID","rahul"));
PreparedQuery pq = ds.prepare(q);
for (Entity result : pq.asIterable())
{
String title = (String) result.getProperty("url");
resp.getWriter().println(title);
}
And this is my DataStore Instance for "Upload" Entity :
But, I am getting a blank page when launching the app .
As addFilter() is deprecated, you may also use following code:
To create a single filter:
query.setFilter(new Query.FilterPredicate("UID", FilterOperator.EQUAL, "rahul"));
To create multiple filters:
After you build all of your filters, combine them together using a CompositeFilter:
new CompositeFilter(CompositeFilterOperator.AND, Arrays.asList(filter1, filter2));
Then set it as the filter to your query by writing:
query.setFilter(composite_filter);
It should give the desired output. If it is giving blank page then kindly check logs in Google Dashboard or shared logs.

Search twitter by language

In twitter by using lang operator you can search for retrieving tweets from a particular language: For example, the following search will return tweets only in english:
https://twitter.com/search?q=lang:en
Is there a way to achieve this using twitter api, especially using twitter4j. I know there is a language attribute for search but it also requires at least one keyword to make a search, I would like to search by a particular language without giving any keyword query. The following command in java driver returns the following error:
Query searchQuery = new Query() //
.count(resultsPerPage) //
.since(since)//
.lang("en");
400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - Query parameters are missing
code - 25
Cheers
You must pass the same do you use in the twitter search, your query will be like:
new Query("lang:en")
Using twitter4j,
Query query = new Query();
query.setLang("en");
query.setQuery(searchQuery);

Categories