in a Windows 10 UWP I try use WebAuthenticationCoreManager.RequestTokenAsync to get the result from a login with a Microsoft account.
I get a WebTokenRequestResult with Success. ResponseData[0] contains a WebAccount with an ID - but the UserName is empty.
The scope of the call is wl.basic - so I should get a lot of information...
I'm not sure how to retrieve extra information - and for the current test the Username would be OK.
I checked out the universal samples - and there I found a snippet which tries to do what I'm trying - an output of webTokenRequestResult.ResponseData[0].WebAccount.UserName.
By the way - the example output is also empty.
Is this a bug - or what do I (and the MS in the samples) have to do to get the users profile data (or at least the Username)?
According to the documentation (https://learn.microsoft.com/en-us/windows/uwp/security/web-account-manager), you have to make a specific REST API call to retrieve it:
var restApi = new Uri(#"https://apis.live.net/v5.0/me?access_token=" + result.ResponseData[0].Token);
using (var client = new HttpClient())
{
var infoResult = await client.GetAsync(restApi);
string content = await infoResult.Content.ReadAsStringAsync();
var jsonObject = JsonObject.Parse(content);
string id = jsonObject["id"].GetString();
string name = jsonObject["name"].GetString();
}
As to why the WebAccount property doesn't get set... shrugs
And FYI, the "id" returned here is entirely different from the WebAccount.Id property returned with the authentication request.
Related
I am trying to move data from a SPARQL endpoint to a JSONObject. Using RDF4J.
RDF4J documentation does not address this directly (some info about using endpoints, less about converting to JSON, and nothing where these two cases meet up).
Sofar I have:
SPARQLRepository repo = new SPARQLRepository(<My Endpoint>);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "SPARQL/JSON");
repo.setAdditionalHttpHeaders(headers);
try (RepositoryConnection conn = repo.getConnection())
{
String queryString = "SELECT * WHERE {GRAPH <urn:x-evn-master:mwadata> {?s ?p ?o}}";
GraphQuery query = conn.prepareGraphQuery(queryString);
debug("Mark 2");
try (GraphQueryResult result = query.evaluate())
this fails because "Server responded with an unsupported file format: application/sparql-results+json"
I figured a SPARQLGraphQuery should take the place of GraphQuery, but RepositoryConnection does not have a relevant prepare statement.
If I exchange
try (RepositoryConnection conn = repo.getConnection())
with
try (SPARQLConnection conn = (SPARQLConnection)repo.getConnection())
I run into the problem that SPARQLConnection does not generate a SPARQLGraphQuery. The closest I can get is:
SPARQLGraphQuery query = (SPARQLGraphQuery)conn.prepareQuery(QueryLanguage.SPARQL, queryString);
which gives a runtime error as these types cannot be cast to eachother.
I do not know how to proceed from here. Any help or advise much appreciated. Thank you
this fails because "Server responded with an unsupported file format: application/sparql-results+json"
In RDF4J, SPARQL SELECT queries are tuple queries, so named because each result is a set of bindings, which are tuples of the form (name, value). In contrast, CONSTRUCT (and DESCRIBE) queries are graph queries, so called because their result is a graph, that is, a collection of RDF statements.
Furthermore, setting additional headers for the response format as you have done here is not necessary (except in rare circumstances), the RDF4J client handles this for you automatically, based on the registered set of parsers.
So, in short, simplify your code as follows:
SPARQLRepository repo = new SPARQLRepository(<My Endpoint>);
try (RepositoryConnection conn = repo.getConnection()) {
String queryString = "SELECT * WHERE {GRAPH <urn:x-evn-master:mwadata> {?s ?p ?o}}";
TupleQuery query = conn.prepareTupleQuery(queryString);
debug("Mark 2");
try (TupleQueryResult result = query.evaluate()) {
...
}
}
If you want to write the result of the query in JSON format, you could use a TupleQueryResultHandler, for example the SPARQLResultsJSONWriter, as follows:
SPARQLRepository repo = new SPARQLRepository(<My Endpoint>);
try (RepositoryConnection conn = repo.getConnection()) {
String queryString = "SELECT * WHERE {GRAPH <urn:x-evn-master:mwadata> {?s ?p ?o}}";
TupleQuery query = conn.prepareTupleQuery(queryString);
query.evaluate(new SPARQLResultsJSONWriter(System.out));
}
This will write the result of the query (in this example to standard output) using the SPARQL Query Results JSON format. If you have a non-standard format in mind, you could of course also create your own TupleQueryResultHandler implementation.
For more details on the various ways in which you can process the result (including iterating, streaming, adding to a List, or just directly sending to a result handler), see the documentation on querying a repository. As an aside, the javadoc on the RDF4J APIs is pretty extensive too, so if your Java editing environment has support for displaying that, I'd advise you to make use of it.
I'm developing an application that tracks exchange email messages in our company.
We where able to get info out from the tracking log, but in the log -by design- there is no subject or body message.
So the next step for us was using EWS to get the message detail when needed.
The question is that in the tracking log we find to IDs :
MessageId in format "F533E7F015A2E24F8D8ABFE2587117C601EDF245#blstex02.subdomain.domain.com"
and
InternalMessageId in format "5840818"
If in EWS we use this id to find the message by id we always get an "Id is malformed." exception.
Here is the code we use:
public static EmailMessage GetEmailById(string uNameToImpersonate, string StringItemId)
{
return EmailMessage.Bind(GetService(uNameToImpersonate), new ItemId(StringItemId));
}
I'm a newbie to EWS so maybe I'm missing something really easy...
Thanks for your help
You can only bind to a Message using the EWSId see https://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx for a more detailed discussion.For the InternetId you will need to search for messages with that particular Id using the findItem operation eg something like
ItemView ivew = new ItemView(1);
service.TraceEnabled = true;
ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
SearchFilter sf = new SearchFilter.IsEqualTo(PidTagInternetMessageId, "F533E7F015A2E24F8D8ABFE2587117C601EDF245#blstex02.subdomain.domain.com");
FindItemsResults<Item> iCol = service.FindItems(WellKnownFolderName.Inbox, sf, ivew);
foreach (Item item in iCol.Items)
{
Console.WriteLine(item.Subject);
}
Using the code examples provided by Independentsoft:
PropertyName myPropertyName = new PropertyName("Disabled", StandardPropertySet.PublicStrings, MapiPropertyType.String);
Exists restrictionExists = new Exists(myPropertyName);
response = service.FindItem(StandardFolder.Inbox, MessagePropertyPath.AllPropertyPaths, new Not(restrictionExists));
we are getting the message but the BodyHtmlText is null...
Using Exchange Server 2010 SP2.
Anyone had any problems with this?
FindItems doesn't return the body (and a number of other properties) you need to make a GetItem Request on the Item in question to get these properties see https://msdn.microsoft.com/en-us/library/bb508824.aspx
I am trying to automate API requests using postman. So first in POST request I wrote a test to store all created IDs in Environment : Which is passing correct.
var jsondata = JSON.parse(responseBody);
tests["Status code is 201"] = responseCode.code === 201;
postman.setEnvironmentVariable("BrandID", jsondata.brand_id);
Then in Delete request I call my Environment in my url like /{{BrandID}} but it is deleting only the last record. So my guess is that environment is keeping only the last ID? What must I do to keep all IDs?
Each time you call your POST request, you overwrite your environment variable
So you can only delete the last one.
In order to process multiple ids, you shall build an array by adding new id at each call
You may proceed as follows in your POST request
my_array = postman.getEnvironmentVariable("BrandID");
if (my_array === undefined) // first time
{
postman.setEnvironmentVariable("BrandID", jsondata.brand_id); // creates your env var with first brand id
}
else
{
postman.setEnvironmentVariable("BrandID", array + "," + jsondata.brand_id); // updates your env var with next brand id
}
You should end up having an environment variable like BrandId = "brand_id1, brand_id2, etc..."
Then when you delete it, you delete the complete array (but that depends on your delete API)
I guess there may be cleaner ways to do so, but I'm not an expert in Postman nor Javascript, though that should work (at least for the environment variable creation).
Alexandre
I'm using the Exchange Web Services Managed API to search a message folder using FindItems. The code I'm using is this:
var search = new SearchFilter.ContainsSubstring(
ItemSchema.Subject,
"subject I want");
ItemView searchView = new ItemView(9999);
searchView.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
EmailMessageSchema.From);
searchView.OrderBy.Add(
ItemSchema.DateTimeReceived,
SortDirection.Descending);
searchView.Traversal = ItemTraversal.Shallow;
var searchResults = _service.FindItems(
folderToSearch.Id,
search,
searchView);
The search works fine, and the properties I've specified in the searchView.PropertySet do get returned. The problem is that it doesn't return all of the details of From.
I iterate searchResults, and cast the items to type EmailMessage or PostItem as appropriate, to access the From property, which returns an EmailAddress object. On that object, the Name property is set, but Address is null.
If I then bind the item, like:
var boundItem = Item.Bind(_service, message.Id);
var boundItemEmail = boundItem as EmailMessage;
Then boundItemEmail.From.Address is not null, it returns the senders email address.
The trouble is, binding a message can be a rather time-consuming process, compared to the much faster FindItems operation.
You should be able to use the LoadPropertiesForItems method to get the From property, it's faster than binding to individual messages.