I tried using example API but seems some of the parameters missing.
This is the API I tried.
public W_AddressStateCity GetAddressStateCityInfo(W_CustomerAddress oAddress)
{
W_AddressStateCity oAddStateCity = new W_AddressStateCity();
var client = new ClientBuilder(AuthID, AuthToken).BuildUsStreetApiClient();
var lookup = new Lookup
{
Street = oAddress.AddressStreetAddress1,
Street2 = oAddress.AddressStreetAddress2,
City = oAddress.AddressCity,
State = oAddress.AddressState,
ZipCode = oAddress.AddressZipCode
};
try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
// Console.WriteLine(ex.Message);
// Console.WriteLine(ex.StackTrace);
}
var candidates = lookup.Result;
oAddStateCity.Country = candidates[0].Metadata.Country;
oAddStateCity.State = candidates[0].Metadata.State;
oAddStateCity.County = candidates[0].Metadata.CountyName;
oAddStateCity.City = candidates[0].Metadata.City;
return oAddStateCity;
}
Only CountyName is available in candidates. The address is always validated before fed into this API.
How I could read Country, State and City ?
I want to read that information from the API, nit from my provided address.
I assume you are referring to the "US Street Address API". SmartyStreets has multiple APIs.
If you look at the US Street Address API documentation on the SmartyStreets site you can see an Example Output - Valid Address section that shows you the common data that is returned.
In the "components" object you can see the city_name and state_abbreviation. If you look in the "metadata" object you can see the county_name.
If you are hitting the "US Street Address API" then all addresses will have "USA" as the country. There is no need to return that. If you use the "International Street Address API" you will have country information included.
Related
I'm creating a booking car app and I'm struggling with update driver car infos. I'm using a real time database with firebase and I want to display the current driver infos and give him to possibility to change his current car informations. I don't know how to display only the current logged driver infos. I read a lot of posts about the same topic but all were using auth with email. I also tried
await firebase.Child("Driver Vehicules").Child(auth.CurrentUser)
but it shows an error. How do I get only the current logged user url in Firebase? The following code display all the users, not just a single one.
public async Task<List<CarAndDriverDisplayInfos>> GetDriverInfos()
{
return (await firebase
.Child("Driver Vehicules")
.OnceAsync<CarAndDriverDisplayInfos>()).Select(item => new CarAndDriverDisplayInfos
{
FNameDriver = item.Object.FNameDriver,
LNameDriver = item.Object.LNameDriver,
CTypeDriver = item.Object.CTypeDriver,
CModelDriver = item.Object.CModelDriver,
YCarDriver = item.Object.YCarDriver,
ImageCarUrl = item.Object.ImageCarUrl,
ImageDriverUrl = item.Object.ImageDriverUrl,
CarIdDriver = item.Object.CarIdDriver,
PersonId = item.Object.PersonId
}).ToList();
}
protected async override void OnAppearing()
{
base.OnAppearing();
var Driver = await firebaseHelper.GetDriverInfos();
lstPersons.ItemsSource = Driver;
}
I've been trying to get my app to delete contacts from the an android phone using C# and Xamarin Forms. I would like to be able to search for a contact by the contact's display name and then delete it from the contacts.
Any help would be greatly appreciated.
Edit
I have now been able to delete all contacts from the phone in one go, but I still want to be able to delete selected contacts using the display name to identify the contact. This is my code, what changes would I have to make to be able delete selected contacts?
List<ContentProviderOperation> ops = new List<ContentProviderOperation>();
ops.Add(ContentProviderOperation.NewDelete(ContactsContract.RawContacts.ContentUri).Build());
Android.App.Application.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
So after a lot of work on it this is my solution. ToDelete is the string I have passed in the compare to the display name of the contact.
Context thisContext = Android.App.Application.Context;
string[] Projection = new string[] { ContactsContract.ContactsColumns.LookupKey, ContactsColumns.DisplayName };
ICursor cursor = thisContext.ContentResolver.Query(ContactsContract.Contacts.ContentUri, Projection, null, null, null);
while (cursor != null & cursor.MoveToNext())
{
string lookupKey = cursor.GetString(0);
string name = cursor.GetString(1);
if (name == ToDelete)
{
var uri = Uri.WithAppendedPath(ContactsContract.Contacts.ContentLookupUri, lookupKey);
thisContext.ContentResolver.Delete(uri, null, null);
cursor.Close();
return;
}
}
Using Autonomy WorkSite 8.5 SP2 SDK, I am attempting to programmicaly add a shortcut to another users My Matters which I have been told can be done by first subscribing to the other users My Matters, add the shortcut then unsubscribe.
I am therefore attempting to subscribe to another users My Matters however I am having issues with how to subscribe, with the below code I am able to locate the user's My Matters:
Dim objSFSP As IManSubscriptionFolderSearchParameters = oDms.CreateSubscriptionFolderSearchParameters
objSFSP.Add( imFolderAttributeID.imFolderOwner, sShortcutUser )
Dim objFolders As IManFolders = oMatters.FindRootSubscriptionFoldersNotSubscribedTo(oDatabaseList, objSFSP)
And from reading the COM Reference guide I should be able to subscribe to a users My Matters with the following code:
Dim objWorkArea As IManWorkArea = oSess.WorkArea
Dim oFolderShortcuts As IManSubscriptionFolderShortcuts = objWorkArea.SubscriptionFolder.SubFolders
Dim oFolderShortcut As IManFolderShortcut = oFolderShortcuts.AddNewSubscriptionFolderShortcutInheriting(objFolders)
The problem I am encountering is AddNewSubscriptionFolderShortcutInheriting() expects an object of the type IManSubScriptionFolder where FindRootSubscriptionFoldersNotSubscribedTo() returns a IManFolders object.
Can anyone point me in the direction of what I need to do to get an instance of the users My Matters as a IManSubscriptionFolder object?
Probably my response will be a bit late for you, but I hope that it will help anybody else who will have the same issue.
Answering your question, in order to get an instance of other users My Matters as a IManSubscriptionFolder object you just need to loop through the collection of objFolders and cast each folder to the IManSubScriptionFolder type.
Please find below my working solution:
ManDMS dms = new ManDMS();
string serverName = "dms.server.com";
IManSession session = dms.Sessions.Add(serverName);
string userID = "user";
string password = "password";
session.Login(userID, password);
ManStrings dblist = new ManStrings();
dblist.Add("TargetWsDbName");
IManSubscriptionFolderSearchParameters searchParams = ndms.CreateSubscriptionFolderSearchParameters();
string folderOwner = "AnotherUser";
searchParams.Add(imFolderAttributeID.imFolderOwner, folderOwner);
IManFolders nonSubscribedRootSubscriptionFolders = session.WorkArea.SubscriptionFolder.FindRootSubscriptionFoldersNotSubscribedTo(dblist, searchParams);
foreach (var folder in nonSubscribedRootSubscriptionFolders)
{
//another user's subscription folder
var subscriptionFolder = folder as IManSubscriptionFolder;
if (subscriptionFolder != null)
{
//Current user's subscription folder shortcuts
var subscriptionFolderShortcuts = session.WorkArea.SubscriptionFolder.SubFolders as IManSubscriptionFolderShortcuts;
if (subscriptionFolderShortcuts != null)
{
subscriptionFolderShortcuts.AddNewSubscriptionFolderShortcutInheriting(subscriptionFolder);
}
}
Please note that code from above was included for reference purpose only and it is not a production code.
I want to search for all users on twitter wit a particular account creation date. So does Twitter api allows that? And if yes, how do I do so using twitter4j?
I am not sure whether it is possible or not. However you might use following things.
For example, assume that you are searching users who has been created in 2010-03-05 (yyyy-MM-dd)
You can create a query like below by giving since and until date points like 1 day before to since point and 1 day later to until point. Because there is no explicit field to set exact date, I came up with this idea. Then, you should call SearchUsers() method with paging mechanism. You can explore how to implement pagination in this, I don't remember how it was, but you can easily find a sample on the Internet. Try the following codes, I hope it will work:
try
{
Query query = new Query();
query.setSince("2010-03-04");
query.setUntil("2010-03-06");
ResponseList<User> userList = twitterObj.searchUsers(query.toString(), -1);
for (User userItem : userList)
{
// Then here you can do whatever you want by using userItem object
}
}
catch (TwitterException ex)
{
// Do necessary error handling mechanism here
}
public void tweetSearch(String queryRequest) throws IOException, TwitterException{
// Create configuration builder and set key, token etc
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("xxxxx");
// type your provided Consumer key and consumer secret key from twitter
//and leave access token access secret token as blank
cb.setOAuthConsumerSecret("xxxx");
cb.setOAuthAccessToken("xxxx");
cb.setOAuthAccessTokenSecret("xxxx");
// Create Twitter instance
Twitter Twitter = new TwitterFactory(cb.build()).getInstance();
// Create file writer and buffer writer
FileWriter fstream = new FileWriter("Twitterstream.txt",true);
BufferedWriter out = new BufferedWriter(fstream);
// Create Query object and set search string
Query query = new Query("");
//change the date as u wish...
query.setSince("2014-06-12");
query.setUntil("2014-06-14");
query.setQuery(queryRequest);
// Get query result
QueryResult qr = Twitter.search(query);
// Get tweets and write in the file
while(qr.hasNext()){
qr.nextQuery();
List<Status> tweets = qr.getTweets();
for (Status t: tweets){
System.out.println(t.getId() + " - " + t.getCreatedAt() + ": " + t.getText());
out.write("\n"+t.getId()+",");
out.write("\t"+t.getText()+",");
out.write("\t"+t.getUser()+",");
}
}
System.out.println("Generated Twitter Stream");
}
I have a neo4j social network db and have a usecase to look through a bunch of user ids and check how many user ids are present in the graph. The User looks like this :
#NodeEntity
public class User {
#GraphId
Long nodeId;
#Indexed(indexName = "uid",unique = true)
Long uid;
}
my check would look somrthing like this :
for(Long uid : allUserIds){
User friend = userRepo.findByPropertyValue("uid", uid);
if(friend!=null){
//Create a relationship
}else{
//continue
}
}
Is there a way I can get rid of the findByPropertyValue for every single userId ? Is there a faster way thru which I can get all existing Users given a bunch of uids in one request ?
Thanks..
You could try with a Cypher query:
Map<String, Object> params = new HashMap<String, Object>();
String query = "start user=node:__types__(className=\"<package>.User\") where ID(user)>=0 and ID(user) in {uids} return user"; // substitute <package> with the full package name
params.put("uids", allUserIds); // allUserIds should be a Collection<Long>
Collection<User> users = neo4jOperations.query(query.toString(), params).to(User.class).as(Collection.class);
for (User user: users) {
...
}
You're already doing it right.
There is also findByQuery afaik, that allows you to pass in a lucene query which would be "uid: value1 value2 value3"