I'm trying to get a Google Classroom Course in C# using its Project Alias.
On the API Documentation page I can get the course no problem using ID or Alias.
For talking sake, let's say:
ID - 123456
Alias - p:abc
When I try on the Documentation page I get a 200 response and retrieve the course when I use either of the above.
However, when in code I can only get the course using the ID. When I try to do it using the alias I get the following error: 404 course not found.
var id= "123456";
var alias = "p:abc";
var request = classroomService.Courses.Get (id);
var course = request.Execute(); //200 response, course is the JSON course
request = classroomService.Courses.Get(alias);
course = request.Execute(); //404 - COURSE NOT FOUND
Not sure if I have to somehow specify the request is using a project-alias but I can't seem to see any options within the request to suggest this.
Thanks
EDIT: Just to add to this, I have tested using a domain alias,
alias - "d:xyz"
This works fine in code, so it appears it is just the project wide alias that isn't working.
As the documentation says, project aliases are visible only by the same project id that created them.
A project-scoped alias is visible to any request from an application using the Developer Console project ID that created the alias and can be created by any project.
Since the project ID used to create the aliases is different from the one used to call the .get() method it will return a 404 - Course Not Found error.
Related
I am trying to confirm that a folder has been uploaded to my Website folder so that it can be accessed by a Desktop application. I keep getting an error that states that there is a URI format error on the connection string. There is no shortage of 'solutions' on the general internet but I cannot get anything to work, even ones on this site (of which I am a member for many years). Forward slashes, back slashes, no slashes ... on and on. I am thoroughly confused. The following seems to be a simple and correct code, but it does not work either even though it is a direct copy of a solution that was offered as correct! The passed string 's' is the name of the folder I am trying to look for. A polite simple answer, perhaps with an example, is my desperate request. Thank You.
private bool CheckFiles(string s)
{
bool exists = System.IO.Directory.Exists(#"\\\\http:/www.myserver.com/sites/"+ s);
return exists;
}
System.IO.Directory.Exists checks for a directory in the file system. The address that is provided as a parameter is a http-URL that is not supported by file system access.
If you want to check for the presence of the folder on a webserver, you need to use a http client to "talk" to the server. Send a GET or HEAD request to the URL. If this returns a 200 (ok), the folder exists, if it returns 404 (not found), it doesn't.
As you are using .NET Framework 4.5 (or 4.0), you can use WebClient or better HttpClient for this. The following should give you an idea of how to check for the folder:
using (var http = new HttpClient())
{
using (var req = new HttpWebRequest(HttpMethod.Head, "https://..."))
{
using (var resp = http.Send(req))
{
// This is a very broad condition;
// you can also check the StatusCode property against HttpStatusCode.NotFound
return resp.IsSuccessStatusCode;
}
}
}
The MS Graph rest API surfaces a resourceProvisioningOptions attribute to indicate whether a MS365 group is also a Team (see below). However, those values do not appear to be available in the GraphServiceClient.
I found this post, and used the sites endpoint to get the associated SharePoint URL for an M365 group. But some M365 groups have SharePoint sites and are not Teams.
The only other option I found was to use the teams endpoint and catch the exception when no team is found for the group ID. But then I still have to do the additional sites endpoint query to get the SharePoint URL.
Does anyone know of another/better way to distinguish between Team/non-Team M365 groups when using the GraphServiceClient?
I'd like to pile on to the helpful post by Baker_Kong.
This functionality is available in both the beta and v1.0 endpoints. It is not described in the v1.0 metadata (which we use to generate the model) and that is why you aren't seeing this in the object model. Until this is resolved, you could use the beta client or:
// Get only groups that have teams.
var groupsThatHaveTeams = await client.Groups.Request().Filter("resourceProvisioningOptions/Any(x:x eq 'Team')").GetAsync()
// When the metadata is fixed, each group will have a ResourceProvisioningOptions property that you can inspect for the 'Team' value.
// Until then, you'd need to look at the Group.AdditionalData dictionary for the resourceProvisioningOptions key and check if it has the 'Team' value.
var groupsThatMayHaveTeams = await client.Groups.Request().Select("id,resourceProvisioningOptions").GetAsync();
cross posted from https://github.com/microsoftgraph/msgraph-sdk-serviceissues/issues/44#issuecomment-752775347
#Tracy,
I have a test the SDK in a console app, I believe this property is under the group entity:
or you can add select option to omit the returned properties:
graphClient.Groups.Request().Select("id,resourceProvisioningOptions").GetAsync().Result;
BR
I am using the Nuget package Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
I have created a Custom Vision application in the Custom Vision portal and obtained API keys and a project ID.
Whenever I try to make a request to the API, I always get the following exception thrown:
HttpOperationException: Operation returned an invalid status code
'NotFound'
Here is my code:
HttpClient httpClient = new HttpClient();
CustomVisionPredictionClient customVisionPredictionClient = new CustomVisionPredictionClient(httpClient, false)
{
ApiKey = PredictionKey,
Endpoint = PredictionEndpoint,
};
var result = customVisionPredictionClient.PredictImageAsync(CUSTOM_VISION_PROJECT_GUID, imageData);
I have tried several different endpoints:
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction
https://southcentralus.api.cognitive.microsoft.com/customvision/Prediction/v1.0
https://southcentralus.api.cognitive.microsoft.com/customvision/v1.1/Prediction
though on the portal the listed one is the first of the list. I have also succesfuly exported my app on Azure, which gives me the second endpoint in the list but with no more success.
I have also set a default iteration as suggested in a similar issue that I found ( CustomVision: Operation returned an invalid status code: 'NotFound' ).
I have tried this sample https://github.com/Microsoft/Cognitive-CustomVision-Windows/tree/master/Samples/CustomVision.Sample which uses a deprecated windows client, to at least ensure my project information are correct and I was able to access the API.
Any insight would be appreciated
For the .NET client SDK, you need to specify the base endpoint URL without the version or the rest of the path. The version is automatically added by the client SDK. In other words, you'll want (assuming SouthCentralUS is your region):
PreditionEndpoint = "https://southcentralus.api.cognitive.microsoft.com";
CustomVisionPredictionClient customVisionPredictionClient = new CustomVisionPredictionClient()
{
ApiKey = PredictionKey,
Endpoint = PredictionEndpoint,
};
var result = customVisionPredictionClient.PredictImageAsync(CUSTOM_VISION_PROJECT_GUID, imageData);
As an aside, note that unless you want to fine-tune the behavior, you don't need to pass in an HttpClient object to CustomVisionPredictionClient constructor.
If you need more sample code, please take a look at the QuickStart.
How to use the Prediction API
If you have an image URL:
your endpoint would be something like this
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/{Project-GUID}/url?iterationId={Iteration-ID}
Set Prediction-Key Header to : predictionId
Set Content-Type Header to : application/json
Set Body to : {"Url": "https://example.com/image.png"}
Or If you have an image file:
Endpoint would be like
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/{ProjectGuid}/image?iterationId={Iteration-Id}
Set Prediction-Key Header to : Predcition-key
Set Content-Type Header to : application/octet-stream
Set Body to : <image file>
Remember, you can mark an iteration as Default so you can send data to it without specifying an iteration id. You can then change which iteration your app is pointing to without having to update your app.
Check my other answer on the similar issue using python
Python custom vision predictor fails
Hope it helps.
We are using alias email addresses to match incoming emails with a client. All the alias addresses are delivered into one Primary emailbox.
The alias address is not listed in the ToRecipients. If I open the email in OWA and look at the message details, I can see the alias in the To: property of the message header.
I tried using the graph.microsoft.com/beta endpoint to get the internetMessageHeader. It worked great(I was surprised.) Unfortunately, the To: property is missing from the response. (The From: property is missing too.)
The problem is the same as this question about using EWS. Exchange Web Services (EWS) API "To" header for alias
Is there an equivalent way to get the PR_TRANSPORT_MESSAGE_HEADERS 0x007D property using the Microsoft-Graph API .Net?
I tried:
var myvar = await graphClient.Users[inbox].Messages[message.Id].Request().Select("transportMessageHeaders").GetAsync();
But I got this error: Message: Could not find a property named 'transportMessageHeaders' on type 'Microsoft.OutlookServices.Message'.
Yes, you can access MAPI properties as extended properties in the Microsoft Graph API.
The URL construct you'd want would look something like:
GET /me/messages/{message-id}?$expand=singleValueExtendedProperties(
$filter=id eq 'String 0x007D')
Since you're using the .NET Graph library, you would modify your code above like so:
var myvar = await graphClient.Users["user"]
.Messages[message.Id]
.Request().Select("singleValueExtendedProperties")
.Expand("singleValueExtendedProperties($filter=id eq 'String 0x007D')").GetAsync();
string transportHeaders = myVar.SingleValueExtendedProperties.First().Value;
I am developing a server application that should be able to react to the amount of likes for some of the posts in the user's feed.
I need to get post from users wall.
I'm using Facebook library version 6.4.2
I use the following code to get the posts:
var apiKey = ConfigurationManager.AppSettings["apiKey"];
var secret = ConfigurationManager.AppSettings["secret"];
var client = PostHandler.CreateFacebookClient(apiKey, secret);
var get = client.Get(string.Format("/{0}/feed", pageId));
and/or (both return the same info)
var token =ConfigurationManager.AppSettings["token"];
var get = client.Get(string.Format("/{0}/feed?access_token={1}", pageId, token));
The problem is that using the same set of permissions the json returned from the request above is different from the json returned from json returned from Graph API Explorer methog GET 100000481752436/feed
In my opinion the json returned from my request is missing some posts and the one from the Geaph API all contains the posts from my feed.
Could you please advice, what could I have missed ?
If you are missing some posts in the feed it is most likely that you'll have to check the permissions set again.
Based on the type of posts you are missing you maybe have to add the user_status, user_activities, user_friends, user_checkins or user_games_activity permissions. Please make sure that you're using the correct set of the permissions for your particular task.
If you'll specify the type of the posts you are missing you may get much more helpful answers.