Google Classroom API : Unable to receive push notifications for courseworks and student submissions (COURSE_WORK_CHANGES) - google-cloud-platform

We are seriously blocked. We have followed the documentation below (among many others) to set up the pub/sub pipelines, create service accounts, assign permissions and use the right scopes and feed types for registrations.
https://developers.google.com/classroom/guides/push-notifications
So programmatically we are able to do the following in .net using the API :
We can Create Courses
We can create registrations for a given courseid
We create/update courseworks for the course that we have created a registration.
All good so far,
BUT, we don't receive notifications for that created/update course work.
some code for clarity :
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("sa-something#precise-asset-259113.iam.gserviceaccount.com")
{
User = "impersonated user",
Scopes = new string[] { "https://www.googleapis.com/auth/classroom.coursework.students" ,
"https://www.googleapis.com/auth/classroom.courses",
"https://www.googleapis.com/auth/classroom.push-notifications" }}
.FromPrivateKey("My private key"));
//Authorize request
var result = credential.RequestAccessTokenAsync(CancellationToken.None).Result;
var service = new ClassroomService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
});
// We get courses
var courses = service.Courses.List().Execute();
// We get one course for registration
var course = courses.Courses.First();
// We create registration
var registration = service.Registrations.Create(new Google.Apis.Classroom.v1.Data.Registration()
{
Feed = new Google.Apis.Classroom.v1.Data.Feed()
{
FeedType = "COURSE_WORK_CHANGES",
CourseWorkChangesInfo = new Google.Apis.Classroom.v1.Data.CourseWorkChangesInfo()
{
CourseId = course.Id
},
},
CloudPubsubTopic = new Google.Apis.Classroom.v1.Data.CloudPubsubTopic()
{
TopicName = "projects/precise-asset-259113/topics/test"
},
});
//Successful response - We get a registrationID
var response = registration.Execute();
var courseWork = new CourseWork()
{
CourseId = course.Id,
Title = "Ver Test",
Description = "Calculus",
WorkType = "ASSIGNMENT",
MaxPoints = 20.0,
State = "PUBLISHED",
AlternateLink = "www.uni.com",
CreatorUserId = course.OwnerId,
CreationTime = DateTime.UtcNow,
DueTime = new TimeOfDay() { Hours = 5, Minutes = 10, Nanos = 10, Seconds = 10 },
DueDate = new Date() { Day = 3, Month = 12, Year = 2019 },
Assignment = new Assignment() { StudentWorkFolder = new DriveFolder() { AlternateLink = "Somewhere", Title = "My Calculus" } }
};
//Create course work for the course that we registered
var courseWorkResponse = service.Courses.CourseWork.Create(courseWork, course.Id).Execute();
SubscriberServiceApiClient subscriber = SubscriberServiceApiClient.Create();
SubscriptionName subscriptionName = new SubscriptionName("precise-asset-259113", "test");
PullResponse pullResponse = subscriber.Pull(
subscriptionName, returnImmediately: true, maxMessages: 20);
// Check for push notifications BUT ....NADA!!!
foreach (ReceivedMessage msg in pullResponse.ReceivedMessages)
{
string text = Encoding.UTF8.GetString(msg.Message.Data.ToArray());
Console.WriteLine($"Message {msg.Message.MessageId}: {text}");
}
Can you please assist?
Thanks

There are several things you need to change in order to ensure you get the notifications:
You need to create your subscription before you send the request that will generate the Pub/Sub message. Only messages published after the successful creation of a subscription are guaranteed to be received by subscribers for that subscription.
A single pull request with returnImmediately set to true is unlikely to return any messages, even if a message has been published. With this property set, if there are no messages immediately in memory of the server reached, the empty response is returned. You should always set returnImmediately to false. This still won't guarantee that messages are returned in a single request/response, even if there are messages available, but it will make it more likely.
Ideally, you would use the asynchronous client library, which opens a stream to the Cloud Pub/Sub service and receives messages as soon as they are available. If you are going to use the synchronous Pull method directly, then you need to keep many of them outstanding simultaneously in order to ensure delivery of messages with minimal latency. As soon as you receive a PullResponse for any of the outstanding requests, you should immediately open up another request to replace it. The goal of the asynchronous client library is to prevent one from having to take all of these step manually to ensure efficient delivery.

Related

WSO2 scim api /Groups/roleId takes too much time to update

I am using WSO2 IS 5.10 version. As per requirement we can add and remove new roles form our application and call the following API to update groups with users. I am doing thi sas bulk operation as some time it requires to update as bulk. Even for 1 role update it takes 6 seconds where no of users are 30-40 k and in production where users are 90-95 k takes more than 12 seconds.
Is there any way to update in less time. Am I not following the correct way. Please suggest.
foreach (var role in roles)
{
var groupBulkOperation = new WSO2GroupBulkSCIMResourceOperationSchema();
groupBulkOperation.BulkId = Guid.NewGuid().ToString();
groupBulkOperation.Method = "PATCH";
groupBulkOperation.Path = "/Groups/" + role.value;
groupBulkOperation.Data = new WSO2GroupBulkSCIMResourceDataSchema
{
Operations = new List<WSO2GroupOperationSchema>
{
new WSO2GroupOperationSchema
{
op = "add",
path = "members",
value = new List<Members>
{
new Members
{
display = userName,
value = userId
}
}
}
}
};
requestModel.Operations.Add(groupBulkOperation);
}
var response = await CommonServiceResponceModel(
KeyObj.WSO2BaseURL + "scim2/Bulk",
Method.POST,
SerializeObject(requestModel)

Google Meet: How can i catch the url?

I need to open a new google meet room, and send it. I can't use standard "share" button in app. I need to catch the final url.
I can't catch that with curl (it's not a normal redirect).
My idea is that i need to open a request/link in background or in the same page, wait some second and catch the link, after i can release the page and user can enter.
Do you know something that can help me?
Edit:
Yes, i had miss to tell that i need to generate a room from a click and catch the url from code. Generally, i should to make this with Google Calendar API, but in this case i can't.
I use google Calendar API. I make a webApp for my organization, that from a form (with user information to send togheter meet link) make a google calendar event with google meet room (from google loggedin user account), catch the link and send it by a smsGateway.
function FormForMeet (Args) {
// get calendar name, if it already exists
var meetsCalendar = CalendarApp.getCalendarsByName ('CalendarName');
Logger.log (meetsCalendar.length)
if (meetsCalendar.length> = 1) {
// if some calendar be found, it catch the first, obviously here you can use some differet method. I had choose this because I don't expect to find more than 1
var calendar = meetsCalendar [0] .getId ();
}
else
{
// If miss, create new one.
var calendar = CalendarApp.createCalendar ('CalendarName', {summary: 'descrip Calendar',
// set a color of calendar label :D
color: CalendarApp.Color.PURPLE});
calendar = calendar.getId ();
}
// Call function to create meet
var LinkMeet = CreateConference_ (calendar);
// here you can use what you want for send Args + LinkMeet);
// if you want return link
return LinkMeet;
}
// Function to create Conference. You can obviously use the code up without make a new function.
function CreateConference_ (calendarId) {
// Custom of event, here I created the conferences according to my needs (now, with 1 h / conference)
var now = new Date ();
var start = new Date (now.getTime ()). toISOString ();
var end = new Date (now.getTime () + (1 * 60 * 60 * 1000)). toISOString ();
// generate random string to request
var rdmreqId = genStrg ();
var event = {
"end": {
"dateTime": end
},
"start": {
"dateTime": start
},
"summary": "conferenceName",
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": rdmreqId
}
}
};
// insert event in calendar
event = Calendar.Events.insert (event, calendarId, {
"conferenceDataVersion": 1});
// if use the function you can return the link to send
return event.hangoutLink
}
// random strind
function genStrg () {
var data = "something";
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789! # # $% & <> * -";
for (var j = 2; j <= data.length; j ++) {
text = ""; // Reset text to empty string
for (var i = 0; i <possible.length; i ++) {
text + = possible.charAt (Math.floor (Math.random () * possible.length));
}
return text;
}
}
all google meet links look something like this:
https://meet.google.com/abc-defg-hij
You should be able to just copy and paste this link from your browser page. If someone enters this link, they will be taken to the meet lobby and they can enter at any time.
If you can't access this link for some reason, like if you're on mobile, you have to put your meet code (the abc-defg-hij) at the end of the aforementioned url.
edit: You actually can find the link if you're on mobile by going into your meeting lobby and scrolling down until you get to "joining information". Under that there should be the meeting link and the numbers to join by phone.

Multiple events getting created on creating event in Teams with 100 members using Graph API

I am creating teams event using Graph API in my Azure function. For 10-30 members, I am able to create an event in MS Teams using Graph. It is sending an email notification also to the members for Join meeting.
When I tried with 50-100 members, multiple events getting created and multiple email notification also sending to each member.
Is there any member limitation or my code issue?
DateTime dStartDate = DateTime.Parse(session.SessionStartDateTime);
DateTime dEndDate = DateTime.Parse(session.SessionEndDateTime);
List<Microsoft.Graph.DayOfWeek> dayOfWeeks = new List<Microsoft.Graph.DayOfWeek>();
dayOfWeeks.Add(Microsoft.Graph.DayOfWeek.Monday);
dayOfWeeks.Add(Microsoft.Graph.DayOfWeek.Tuesday);
Event #event = new Event
{
Subject = "Test Meeting",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Online Meeting - Test Meeting"
},
Start = new DateTimeTimeZone
{
DateTime = session.StartDateStartTime,
TimeZone = "Eastern Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = session.StartDateEndTime,
TimeZone = "Eastern Standard Time"
},
Location = new Location
{
DisplayName = "Online"
},
Recurrence = new PatternedRecurrence
{
Pattern = new RecurrencePattern
{
Type = Weekly,
Interval = 1,
DaysOfWeek = dayOfWeeks
},
Range = new RecurrenceRange
{
Type = EndDate,
StartDate = new Date(dStartDate.Year, dStartDate.Month, dStartDate.Day),
EndDate = new Date(dEndDate.Year, dEndDate.Month, dEndDate.Day)
}
};
IsOnlineMeeting = true,
OnlineMeetingProvider = "TeamsForBusiness"
};
List<Attendee> attendees = new List<Attendee>();
if (session?.instructors?.Count > 0)
{
session.instructors.ForEach(s =>
{
attendees.Add(new Attendee
{
EmailAddress = new EmailAddress
{
Address = s.Email,
Name = s.Name
},
Type = AttendeeType.Required
});
});
}
if (session?.shoppers?.Count > 0)
{
session.shoppers.ForEach(s =>
{
attendees.Add(new Attendee
{
EmailAddress = new EmailAddress
{
Address = s.Email,
Name = s.Name
},
Type = AttendeeType.Required
});
});
}
#event.Attendees = attendees;
GraphServiceClient graph = GetAuthenticatedClient(session.tenantADInformation);
Event #event = PrepareEvent(session);
string Email = session.instructors.FirstOrDefault()?.Email;
var Event = await graph.Users[Email].Events
.Request()
.Header("Prefer", "outlook.timezone=\"" + session.TenantTimeZone + "\"")
.AddAsync(#event);
If it is 50-100 attendees then my Event is having Event.IsOnlineMeeting as false(even though I have set that to true) and Event.OnlineMeeting is coming as null.
Can anyone help?
I don't think exist any limitation in this case. Since the api allows us to create the event for the members, we can request it although there are many members. The only factor which may limit it is the max number of members in teams is 500. In addition to this, I think the api and the code can work fine.

Establishing session for Acumatica web services

Establishing session for Acumatica web services
I have a requirement where a session is to be established using web services, and then use that session to perform subsequent actions. E.g. Creating SOOrder and Shipment using web services using a previously created session/token.
SOOrder.Screen content = new SOOrder.Screen();
content.Url = InstanceUrl + “/Soap/SO301000.asmx";
content.CookieContainer = new System.Net.CookieContainer();
SOOrder.LoginResult lresult= content.Login(Username, password);
Using this, I have already obtained a session in lresult.Session.
Now, I would like to use this session in below shipmentcontent without calling login again.
SOShipment.Screen shipmentcontent = new SOShipment.Screen();
shipmentcontent.Url = InstanceUrl + "(W(3))/Soap/SO302000.asmx";
shipmentcontent.CookieContainer = new System.Net.CookieContainer();
shipmentcontent.Login(Username, password);
By package various screens in Web Services (SM.20.70.40) found under System -> Integration -> Configure -> Web Services you create a single end-point for all these screens. Consume this service end-point in you app, login only once and call out to all those screens.
thnx
If I understand you corectly you want to persist your login connection between different actions in Acumatia. In order to achieve this, I used the following approach:
Create graph:
public class Importer : PXGraph
{
}
Inside graph created following code:
public string GetHostUrl()
{
var nextIndex = HttpContext.Current.Request.Url.ToString().IndexOf("/", 7, StringComparison.Ordinal) + 1;
var urlStart = HttpContext.Current.Request.Url.ToString().IndexOf("/", nextIndex + 1, StringComparison.Ordinal);
var url = HttpContext.Current.Request.Url.ToString().Substring(0, urlStart);
return url;
}
public Screen Screen
{
get
{
var context = new Screen
{
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
EnableDecompression = true,
Timeout = 1000000
};
var nextIndex = HttpContext.Current.Request.Url.ToString().IndexOf("/", 7, StringComparison.Ordinal) + 1;
var urlStart = HttpContext.Current.Request.Url.ToString().IndexOf("/", nextIndex + 1, StringComparison.Ordinal);
context.Url = HttpContext.Current.Request.Url.ToString().Substring(0, urlStart) + "/Soap/IMPORTET.asmx";
return context;
}
}
and then between different screens shared context of the Screen.
For example like this:
var scr = Screen;
var userName = PXAccess.GetUserName();
var password = GetUserPassword();
var context = Screen;
var lgRes = context.Login(userName, password);
but I preserved user password between different sessions

Listing Activities via Web Services

I'm trying to reproduce the Activities page in Microsoft CRM 4.0 via web services. I can retrieve a list of activities, and I believe I need to use ActivityPointers to retrieve the entities but have so far been unsuccessful. Would I need to loop through every single entity returned from the first query to retrieve the ActivityPointer for it? And if so, how would I then get the "Regarding" field or Subject of the activity (eg: email).
The code to retrieve the activities is:
var svc = GetCrmService();
var cols = new ColumnSet();
cols.Attributes = new[] { "activityid", "addressused", "scheduledstart", "scheduledend", "partyid", "activitypartyid", "participationtypemask", "ownerid" };
var query = new QueryExpression();
query.EntityName = EntityName.activityparty.ToString();
query.ColumnSet = cols;
LinkEntity link = new LinkEntity();
//link.LinkCriteria = filter;
link.LinkFromEntityName = EntityName.activitypointer.ToString();
link.LinkFromAttributeName = "activityid";
link.LinkToEntityName = EntityName.activityparty.ToString();
link.LinkToAttributeName = "activityid";
query.LinkEntities = new[] {link};
var activities = svc.RetrieveMultiple(query);
var entities = new List<ICWebServices.activityparty>();
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse) svc.Execute(request);
//var pointers = new List<activitypointer>();
foreach (activityparty c in activities.BusinessEntities)
{
entities.Add(((activityparty)c));
//the entities don't seem to contain a link to the email which they came from
}
Not sure if I understand your problem, but the field "activityid" in the activitypointer object is the same activityid as the underlying activity (email, task, phonecall, etc). The regardingobjectid is the link to the regarding entity.
Heres what you need to get the equivalent of the Activities page
ColumnSet cols = new ColumnSet()
{
Attributes = new string[] { "subject", "regardingobjectid", "regardingobjectidname", "regardingobjectidtypecode", "activitytypecodename", "createdon", "scheduledstart", "scheduledend" }
};
ConditionExpression condition = new ConditionExpression()
{
AttributeName = "ownerid",
Operator = ConditionOperator.Equal,
Values = new object[] { CurrentUser.systemuserid.Value } //CurrentUser is an systemuser object that represents the current user (WhoAmIRequest)
};
FilterExpression filter = new FilterExpression()
{
Conditions = new ConditionExpression[] { condition },
FilterOperator = LogicalOperator.And
};
QueryExpression query = new QueryExpression()
{
EntityName = EntityName.activitypointer.ToString(),
ColumnSet = cols,
Criteria = filter
};
BusinessEntityCollection activities = svc.RetrieveMultiple(query);
foreach (activitypointer activity in activities)
{
//do something with the activity
//or get the email object
email originalEmail = (email)svc.Retrieve(EntityName.email.ToString(), activity.activityid.Value, new AllColumns());
}