How to Create Contact in Google inside a group - java

Can any body tell me how i can create a google contact under the group like i have one group by name family under this i want to add the contact. Now i am able to create contact but its going under others following code i am using
ContactEntry contact = new ContactEntry();
contact.setTitle(new PlainTextConstruct("chetan"));
contact.setContent(new PlainTextConstruct("sharma"));
Email primaryMail = new Email();
primaryMail.setAddress("newcontact#gmail.com");
primaryMail.setRel("http://schemas.google.com/g/2005#home");
primaryMail.setPrimary(true);
contact.addEmailAddress(primaryMail);
ExtendedProperty favouriteFlower = new ExtendedProperty();
favouriteFlower.setName("favourite flower");
favouriteFlower.setValue("daisy");
contact.addExtendedProperty(favouriteFlower);
//URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/defaults/full");
contact = service.insert(feedUrl, contact);
GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(false, "http://www.google.com/m8/feeds/groups/defaults/base/39eb8f59897bac4d");
//groupMembershipInfo
contact.addGroupMembershipInfo(groupMembershipInfo);

I see that you are inserting the contact before adding the groupMembershipInfo. If you want to add the group membership details to the contact, move this line "contact = service.insert(feedUrl, contact);" as a last line of the code.
You can refer to this page for more details.
Hope that helps!

You can execute below method and get Atom id for different groups in your account like My Contacts, Family etc.
public static void printAllGroups(ContactsService myService)
throws ServiceException, IOException {
// Request the feed
URL feedUrl = new URL("https://www.google.com/m8/feeds/groups/ankit.ab2502#gmail.com/full");
ContactGroupFeed resultFeed = myService.getFeed(feedUrl, ContactGroupFeed.class);
for (ContactGroupEntry groupEntry : resultFeed.getEntries()) {
System.out.println("Atom Id: " + groupEntry.getId());
System.out.println("Group Name: " + groupEntry.getTitle().getPlainText());
}
}
Output of this method for Family group will be like:
Atom Id: http://www.google.com/m8/feeds/groups/UR_EMAIL_ID/base/e
Use this url to add contact to a Family group
GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(false, "http://www.google.com/m8/feeds/groups/UR_EMAIL_ID/base/e");
contact.addGroupMembershipInfo(groupMembershipInfo);

Related

DocuSign's Java SDK: Add 'Recipient Company Name' to Signer/Recipient

DocuSigns' report section includes tables containing the column name Recipient Company Name
I had a look through all DocuSign models inside the SDK, but I couldn't find any way to fill this column. Is there a way to do so using the SDK?
This can only be filled if the recipient is either a :
Saved contact in your DocuSign account.
Has their own DocuSign account.
If your recipient is just a random email/name you added to a one-time envelope - there's no way to enter the company information.
You can update contacts in your account and add the company name, see this article I wrote about how to do that in 6 languages including Java:
(note the "Organization" field which is the compan)
// You will need to obtain an access token using your chosen authentication flow
Configuration config = new Configuration(new ApiClient(basePath));
config.addDefaultHeader("Authorization", "Bearer " + accessToken);
UsersApi usersApi = new UsersApi(config);
UserProfile userProfile = new UserProfile();
Contact contact = new Contact();
contact.setName("Inbar Gazit");
contact.setEmails(new java.util.ArrayList<String>());
contact.getEmails().add("inbar.gazit#docusign.com");
contact.setOrganization("DocuSign");
ContactPhoneNumber contactPhoneNumber = new ContactPhoneNumber();
contactPhoneNumber.setPhoneNumber("212-555-1234");
contactPhoneNumber.setPhoneType("mobile");
contact.setContactPhoneNumbers(new java.util.ArrayList<ContactPhoneNumber>());
contact.getContactPhoneNumbers().add(contactPhoneNumber);
ContactModRequest contactModificationRequest = new ContactModRequest();
contactModificationRequest.setContactList(new java.util.ArrayList<Contact>());
contactModificationRequest.getContactList().add(contact);
usersApi.postContacts(accountId, contactModificationRequest);

Keycloak: how to programmatically add new subgroups with associated users?

In Keycloak 8.0.1 we have a Realm with a Group and Subgroups like this:
group -
subgroup1
subgroup2
...
We need to insert a batch of subgroups and users into group. The subgroup should have some attributes.
How can I do this?
I tried:
Using an exported realm-export.json file with newly added subgroups and "Overwrite" on the import. Now I don't see how to connect the new user with the subgroup. And I am also not sure if old users will not be removed this way.
Calling the Keycloak REST API. It doesn't seem possible to UPDATE a group and add subgroups. Documentation says:
PUT /{realm}/groups/{id}Update group, ignores subgroups.
Now I am looking at using a UI testing tool to add the user programmatically, but this seems needlessly complex.
Is it possible to programmatically add new subgroups with users associated to that subgroup? Am I missing something with the REST API call or the import functionality? Is there maybe another way via for example the Java Admin Client?
You can create groups and subgroups under it , Here is the sample code to create subgroups using Admin Client. You can also associate users to those groups
public void addSubgroups() {
RealmResource realm =keycloak.realm("myrealm");
GroupRepresentation topGroup = new GroupRepresentation();
topGroup.setName("group");
topGroup = createGroup(realm, topGroup);
createSubGroup(realm,topGroup.getId(),"subgroup1");
createSubGroup(realm,topGroup.getId(),"subgroup2");
}
private void createSubGroup(RealmResource realm, String parentGroupId, String subGroupName) {
GroupRepresentation subgroup = new GroupRepresentation();
subgroup.setName(subGroupName);
try (Response response = realm.groups().group(parentGroupId).subGroup(subgroup)){
if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
System.out.println("Created Subgroup : " + subGroupName );
} else {
logger.severe("Error Creating Subgroup : " + subGroupName + ", Error Message : " + getErrorMessage(response));
}
}
}
private GroupRepresentation createGroup(RealmResource realm, GroupRepresentation group) {
try (Response response = realm.groups().add(group)) {
String groupId = getCreatedId(response);
group.setId(groupId);
return group;
}
}
getCreatedId(response);
This method in above answer (by ravthiru) is belongs to CreatedResponseUtil from package (org.keycloak.admin.client)
CreatedResponseUtil.getCreatedId(response);

how to get the full tweet of the user timeline with twitter4j?

I want to get tweets from certain user timelines using java library twitter4j, currently I have source code which can get ~ 3200 tweets from user time line but I can't get full tweet. I have searched in various sources on the internet but I can't find a solution to my problem. anyone can help me or can anyone provide an alternative to get a full tweet from the user timeline with java programming?
my source code :
public static void main(String[] args) throws SQLException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("aaa")
.setOAuthConsumerSecret("aaa")
.setOAuthAccessToken("aaa")
.setOAuthAccessTokenSecret("aaa");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
int pageno = 1;
String user = "indtravel";
List statuses = new ArrayList();
while (true) {
try {
int size = statuses.size();
Paging page = new Paging(pageno++, 100);
statuses.addAll(twitter.getUserTimeline(user, page));
System.out.println("***********************************************");
System.out.println("Gathered " + twitter.getUserTimeline(user, page).size() + " tweets");
//get status dan user
for (Status status: twitter.getUserTimeline(user, page)) {
//System.out.println("*********Place Tweets :**************\npalce country :"+status.getPlace().getCountry()+"\nplace full name :"+status.getPlace().getFullName()+"\nplace name :"+status.getPlace().getName()+"\nplace id :"+status.getPlace().getId()+"\nplace tipe :"+status.getPlace().getPlaceType()+"\nplace addres :"+status.getPlace().getStreetAddress());
System.out.println("["+(no++)+".] "+"Status id : "+status.getId());
System.out.println("id user : "+status.getUser().getId());
System.out.println("Length status : "+status.getText().length());
System.out.println("#" + status.getUser().getScreenName() +" . "+status.getCreatedAt()+ " : "+status.getUser().getName()+"--------"+status.getText());
System.out.println("url :"+status.getUser().getURL());
System.out.println("Lang :"+status.getLang());
}
if (statuses.size() == size)
break;
}catch(TwitterException e) {
e.printStackTrace();
}
}
System.out.println("Total: "+statuses.size());
}
Update :
After the answer given by #AndyPiper
the my problem is every tweet that I get will be truncated or not complete. a tweets that I get will be truncated if the length of tweet more than 140 characters. I found the reference tweet_mode=extended, but I do not know how to use it. if you know something please tell me.
Your Configuration should be like this:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("aaa")
.setOAuthConsumerSecret("aaa")
.setOAuthAccessToken("aaa")
.setOAuthAccessTokenSecret("aaa")
.setTweetModeExtended(true);
It is explained well here
The Twitter API limits the timeline history to 3200 Tweets. To get more than that you would need to use the (commercial) premium or enterprise APIs to search for Tweets by a specific user.
if you are streaming tweets
fist: you have to add .setTweetModeExtended(true); into your configurationbuilder
second(here is the code)
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener(){
public void onStatus(Status status) {
System.out.println("-------------------------------");
if(status.isRetweet()){
System.out.println(status.getRetweetedStatus().getText());
}
else{
System.out.println(status.getText());
}`
its totally works for me.
take care yourself :)
If you are implementing twitter api using twitter4j.properties file and getting truncated timeline text value,simply add the below property in it at the end.
tweetModeExtended=TRUE

How to get Display Name of Contact by User ID in Applozic?

I am using Digits by Twitter alongside Applozic SDK. I am creating a custom contact list, by using Find Friends provided by Digits, and then using their friends' IDs to get their display name from Applozic.
This my code:
Log.e("Friend ID", user.idStr);
AppContactService appContactService = new AppContactService(context);
Contact contact = appContactService.getContactById(user.idStr);
Log.e("Friend Display Name", contact.getDisplayName());
This is my logcat output:
E/Friend ID: 753958303214870528
E/Friend Display Name: 753958303214870528
E/Friend ID: 751769088456790016
E/Friend Display Name: 751769088456790016
As you can see, even getDisplayName() returns UserID. This is my Applozic Dashboard
.
Is there anything I am doing wrong??
For this you need to make server call and get the User details from server. The above method which your are using it will only check from local data base
You can user this method to get the details from server
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
userIds.add("user3");
UserService.getInstance(context).processUserDetails(userIds); //server call
AppContactService appContactService = new AppContactService(context);
Contact contact = appContactService.getContactById("user1");
if(contact != null){
Log.e("Friend Display Name", contact.getDisplayName());
}

Rally Rest Api: Get User's Email Address from Defect

With Rally's rest api, how can I query to find a user's email address?
For instance, I have this query to get a defect which contains the full name of the user who opened it and the user who owns the defect:
QueryRequest defectRequest = new QueryRequest("defect");
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId"));
defectRequest.setQueryFilter(new QueryFilter("Project.Name", "=", rallyProjectName).and(new QueryFilter("LastUpdateDate", ">", defectTimestamp.getTimestamp())));
QueryResponse projectDefects = rallyApi.query(defectRequest);
Now I'd like to take the Submitted By and Owner users from the defect and get their email addresses.
Make certain to include the fields "Owner" and "SubmittedBy" on your Fetch for the Defects:
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId", "Owner", "SubmittedBy"));
Then the Owner and SubmittedBy fields on each returned Defect (if populated in Rally and not null) will have a reference to the corresponding User object in Rally. Then your inclination to do a second request for this is spot on. It's easiest to just use that ref and do a GetRequest straight against the ref. Here's how on the Owner field as an example (forgive the clumsy try/catch block - it's catching empty Owner fields):
QueryResponse projectDefects = restApi.query(defectRequest);
if (projectDefects.wasSuccessful()) {
for (JsonElement result : projectDefects.getResults()) {
JsonObject defect = result.getAsJsonObject();
try {
JsonObject ownerJsonObject = defect.get("Owner").getAsJsonObject();
String ownerRef = ownerJsonObject.get("_ref").getAsString();
GetRequest ownerRequest = new GetRequest(ownerRef);
GetResponse ownerResponse = restApi.get(ownerRequest);
JsonObject ownerObj = ownerResponse.getObject();
System.out.println(String.format("Read owner. EmailAddress = %s",
ownerObj.get("EmailAddress").getAsString()));
} catch (java.lang.IllegalStateException ise) {
// System.out.println("IllegalStateException caught: ");
// ise.printStackTrace();
}
}
}

Categories