How to call Microsoft Graph Beta API from C# - c#

I tried to get the content of the user's profile picture and I found out that I had to call the Beta version because the current version gives the following error message:
"code": "GetUserPhoto",
"message": "The operation is not supported."
So, I tried to switch to Beta, and here is the code that I wrote in C# to do it, but it doesn't work:
Microsoft.Graph 1.6.2
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$api-version", "beta")
};
var pictureStream = await graphClient.Me.Photo.Content.Request(options).GetAsync();
I got the same error message.
I tried the same request in the Graph Explorer. The 1.0 doesn't work, but Beta works.

The api-version query parameter is used by the Azure AD Graph API. This is a different API than Microsoft Graph. There is a lot of functional overlap (Azure AD Graph is slowly being migrated over to Microsoft Graph) but they use entirely different entities and calling conventions.
In order to call the /beta endpoint using the Microsoft Graph .NET Client Library, you need to change the BaseUrl of the client:
graphClient.BaseUrl = "https://graph.microsoft.com/beta";
var pictureStream = await graphClient.Me.Photo.Content.Request().GetAsync();
Some important notes about the /beta endpoint:
It isn't supported and isn't suitable for production. So don't do that. Or at least don't tell anyone and don't call Support if it stops working. ;-)
The .NET Client uses objects constructed off the production metadata. This means that any entities, actions or properties that were added in /beta don't exist in the models shipped with the SDK.
The .NET Client will ignore any values returned by Microsoft Graph that it doesn't expect to see. So if an endpoint returns a property that wasn't included in the production metadata (see #2), it will simply be ignored.
So long as you're only using a /beta to gain functionality but still expecting /v1.0 results, it should work okay. Photos for example only look at Exchange in v1.0 but look in both Exchange and Active Directory but still return the same result. In theory this means you should be able to swap /beta for /v1.0 without a problem.

I think you are still calling V1 endpoint. In fact, the Beta endpoint is not currently supported in the Microsoft Graph .NET Client Library. More info here.

There is an official beta client for Graph API now:
https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet

Related

Where is IBotDataBag stored in Microsoft Bot using framework v3 SDK?

I've currently got a Bot running in Microsoft Teams, which has been built many years ago using the Microsoft Bot Framework v3 SDK. Now I will show an example of a location where I have saved some data after using the Bot, which I understand is stored in the "IBotDataBag".
So this method is the first method that is called when I enter a message to the Bot in Teams (as a result of the framework). It is injected with an object of type "IDialogContext" and this object contains other objects, one, which is of type "IBotData" and above in the image is "context.UserData". I use this to set some data, for example I had set it to store a value inside the key of "test_data", which I retrieve in the image above.
Now my question is, where in the Bot application is this data actually held? My application is deployed to Azure as an application service. It is installed locally in my Microsoft Teams after installing it from my Org's application catalogue. I want to know whether this data is held somewhere locally on my PC or in the cloud somewhere. Based on a test by uninstalling the Bot I thought if it was held in the cloud then the data set in the "IBotDataBag" would be removed but after installing the Bot after, the information was still present, which leads me to believe the Bot held onto the information locally on my machine. I have tried to find information to support this conclusion online but I have not spotted anything useful so far and I understand Microsoft are now very much pushing SDK v4 so was hoping someone on here can shed some light on the question for me please?
So after reviewing the architecture of the bot in its resource group in the Microsoft Azure portal, I found an entry of type "Storage Account", which is basically Azure Table Storage for the bot. In here there is a section for "Tables" and in here you will find an entry called "botdata". Inside of this table you will find several entries, which are identifiable by their partition key. After running doing some trial and error I found that removing the "msteams:user" entries would result in my bot not having any "UserData" inside of the context object. Based on several tests, I concluded that the data is held in table storage and that the bot framework handles the CRUD operations on this data.
The V3 SDK is being retired with final long-term support ending on December 31st, 2019. Accordingly, there will be no more development in this repo.We highly recommend that you start migrating your V3 bots to V4.
The v3 SDK currently supports two programing language. Bot builder SDK v3 includes samples for all supported languages:
.NET
JavaScript
Here some Code snippest-
private async Task MessageReceivedAsync(IDialogContext context,
IAwaitable result)
{
var activity = await result as Activity;
// An example of a string value saved directly to UserData
context.UserData.SetValue("test", "test");
// If we have not asked the user their name, ask it now
var askedName = context.UserData.GetValueOrDefault<bool>(AskedNameProperty);
if (!askedName)
{
await context.PostAsync($"v3: Hi. What is your name?");
// We've asked the user their name, so persist the information in UserData
context.UserData.SetValue(AskedNameProperty, true);
}
Reference Sample-https://github.com/microsoft/BotBuilder-Samples/blob/4d209edeaaaa72d29279057ff2c1ac3ce213694b/Migration/MigrationV3V4/CSharp/V3StateBot/V3StateBot/Dialogs/RootDialog.cs
Document-https://github.com/microsoft/botbuilder-v3

IBM Watson Unity SDK, IamAuthenticator objects cannot authenticate successfully

I am trying to query Watson Discovery News and get some responses in Unity.
First I tried to authenticate my Watson Discovery service through Discovery service APIKey(As described in the "IAM" section in https://github.com/watson-developer-cloud/unity-sdk). My code is exactly the same as the example code in "Query a collection" section in https://cloud.ibm.com/apidocs/discovery/discovery?code=unity#query-a-collection.
Unfortunately, the code always returns due to unsuccessful authentication, thus I cannot get any response. After some debugging, I found out that "tokenData" field in IamAuthenticator.cs(This is part of IBM Unity SDK) is not initialized; this leads to the unsuccessful authentication.
I was able to debug by changing the "yield return" in example code to "return". Otherwise, C# debugger cannot step into the code.
Since I have followed all the steps in IBM documentations, I am not sure how to proceed.
To reproduce the problem, one has to download IBM Unity SDK on https://github.com/watson-developer-cloud/unity-sdk and follow the instructions in README. After setting up, one could replicate the problem using the code below:
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
Thanks in advance for any help!
Have you set the URL (SetServiceUrl) to match the location for your service instance? See Service Endpoint in the API reference
I bypassed this problem using Token authentication instead of using APIkey.
If one has the choice of using other SDKs, e.g. Java SDK, please do so. Because Watson Unity SDK is not well supported at the moment.

PowerBI Embedded "Provision Token" generation error

I am trying to follow this PowerBI embedded example and am getting an error:
'PowerBIToken' does not contain a definition for 'CreateProvisionToken'
This MSDN article describes the CreateProvisionToken() method.
I installed latest Microsoft.PowerBI.Core and Microsoft.PowerBI.Api using NuGet package manager
included Microsoft.PowerBI.Security and Microsoft.PowerBI.Api.V1 in my project.
I also tried changing CreateProvisionToken() part to the following:
var credentials = new TokenCredentials(accessKey, "AppKey");
var client = new PowerBIClient(credentials);
var devToken = PowerBIToken. CreateDevToken(reportID, workspaceID);
using (client)
{
var embedToken = PowerBIToken.CreateReportEmbedToken(
collectionName,
workspaceID,
reportID);
var embedTokenString = embedToken.Generate(accessKey);
}
Which generates a token which "looks about right", but using this token in the example html in the end of the article results in an error This content is not available when rendering the report.
What am I missing?
The latest version of Power BI embedded simplifies the authentication mechanism by only support one embedded token, no other tokens anymore from Power BI blog:
https://powerbi.microsoft.com/en-us/blog/what-s-new-and-what-s-next-for-power-bi-embedded-july-2016/
We have simplified the way developers authenticate their calls to Power BI. From today on, app tokens will only be used to authenticate embedding requests and other client side requests that may be added in the future. All calls to our REST APIs will be authenticated using our API keys directly. This eliminates the need to generate app tokens each time you want to call the REST API.
You need follow up the example from Microsoft:
https://github.com/Azure-Samples/power-bi-embedded-integrate-report-into-web-app/blob/master/EmbedSample/Controllers/DashboardController.cs

Cannot assign a payer_id when saving a card to the vault

According to the rest api documentation it is recommended to assign a payer_id when saving a card to the vault.
My problem is that there is no payer_id property to populate for the creditCard object in the first place.
creditCard.number = "4417119669820331";
creditCard.expire_month = "11";
creditCard.expire_year = "2018";
creditCard.first_name = "Joe";
creditCard.last_name = "Shopper";
creditCard.type = "visa";
**creditCard.payer_id = "123456789";**
As far as I am aware I am using the latest APIs updated by Nuget in VS2012.
Here's the response from the PayPal Vault API team:
The payer_id field was never removed. We've intended to deprecate/discourage its use because we determined that this field was misleading in the way it was named - it was being mistaken for a PayPal's internal identifier, where in reality, to PayPal, it was just an arbitrary string, intending to identify an externally managed customer id. The Vault team has since added a field named external_customer_id that better captures the intent.
The external_customer_id property (found here in the current version of the SDK) is what should be used instead. However, since the payer_id property will continue to be supported in the v1 version of the Vault REST services, the .NET SDK will continue to provide support for this (the upcoming v1.1 .NET SDK release will include it again).
The PayPal documentation team is working on getting the public documentation for the credit card object updated to include this information.
For future reference by other developers who may find this post, I'd like to add that if you do find a property missing from the PayPal .NET SDK, a better place to report this is to open an issue on the PayPal .NET SDK GitHub repository where the code for the SDK resides.

C# Amazon Product Advertising API

As of August 15, Amazon made it compulsory to sign all requests made to their Product Advertising API. I thought I had got everything working just fine but when the 15th finally came around, my web application stopped working and pretty much ever since I have been trying to find out how to sign the SOAP requests.
Amazon has an outdated sample code for signing requests that doesn't appear to work here
Basically, I need to know how to add a signature to the my requests using the most current C# SOAP API and .NET 3.5.
I hope I have given enough details, if I haven't please feel free to ask me to elaborate.
Thank You
The_Lorax
UPDATE:
I am using MVC and need to know how to add the Signature to the the ItemLookup or AWSECommerceService object. Is there an attribute that contains the signature value? How does it get attached to the request?
On this page, they say that I must include the Signature and TimeStamp parameters but the intellisense does now show any such attributes.
Check out http://flyingpies.wordpress.com/2009/08/01/17/. It has a walkthrough and a sample visual studio solution using C#, SOAP, WCF on .NET 3.5.
This library automatic sign the requests (Install-Package Nager.AmazonProductAdvertising)
https://www.nuget.org/packages/Nager.AmazonProductAdvertising/
Example:
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.SearchItemsAsync("canon eos");

Categories

Resources