How do I create an invitation to a class using the invitations.create() method? - google-classroom

I'm using the Google Classroom API with Python, and am trying to invite a student to a course, using the invitations.create() method. However, I keep getting a "404 requested entity not found" error, and I'm unsure what's causing it.
service = build('classroom', 'v1', credentials=creds)
info = {
"userId": "zariftwitters#gmail.com",
"courseId": "117906298438634973718",
"role": "STUDENT"
}
i = service.invitations().create(body=info).execute()
Error message:
Http Error 404 when requesting
https://classroom.googleapis.com/v1/invitations?alt=json returned
"Requested entity was not found."

Most likely it means that the course Id is incorrect
The course Id should contain 11 numbers.
You can list all courses and their Ids with the method courses.list, the easiest way to do it would be with the Try this API.

Related

Update viewer fields and connection on Store

I'm trying to update the values and connections on my current viewer within the Relay store.
So without calling the mutation signIn if I print:
console.log(viewer.name) // "Visitor"
console.log(viewer.is_anonymous) // true
on Mutations we got the method updater which gives us the store, so in my mutation I'm doing something like this:
mutation SignInMutation($input: SignInInput!){
signIn(input: $input){
user {
id
name
email
is_anonymous
notifications{
edges{
node {
id
...NotificationItem_notification
}
}
}
}
token
}
}
So my updater method has:
const viewer = store.get(viewer_id);
const signIn = store.getRootField('signIn');
viewer.copyFieldsFrom(signIn.getLinkedRecord('user'))
After this I updated the store I got the name email is_anonymous fields updated with the data that just came from the graphql endpoint (I mean now name is "Erick", is_anonymous is now false, which is great), but If I try to do viewer.notifications and render it, the length of the viewer.connections seem to be 0 even when it has notifications.
How can I update my current viewer and add the notifications from the MutationPayload into the store without the need to force fetch?
Im using the latest relay-modern and graphql.
PS: Sorry for the bad formation, but is just impossible to format the code the way OF wants me to, i formated it to 4 spaces and still gave me errors.
With some reorganisation of your GraphQL schema it might be possible to remove the need to interact directly with the Relay store after your sign-in mutation. Consider:
viewer {
id
currentUser {
name
email
}
}
When a user that is not logged in, currentUser would return null.
You could then modify your login mutation to be:
mutation SignInMutation($input: SignInInput!){
signIn(input: $input){
viewer {
id
currentUser {
name
email
token
}
}
}
}
Knowing the 'nullability' of the currentUser field provides an elegant way of determining if the user is logged in or not.
Based on the presence of the token field implies that you are using JWT or similar to track login status. You would need to store this token in local storage and attach it to the headers of the outgoing Relay requests to your GraphQL endpoint if it is present.
Storing the token itself would have to be done in the onCompleted callback of where you make the mutation request (you will have access to the payload returned by the server in the arguments of the callback function).
As an alternative to the token, you could also explore using cookies which would provide the same user experience but likely require less work to implement then JWT tokens.

Using New Google API Console project getting unauthorized_client ,Client is unauthorized to retrieve access tokens using this method

I created a Google API Console project and client ID with web application type.Then Using OAuth 2.0 Playground - Google Developers I authorized to drive, sheet and calendar scopes using my client id.
Also, Service account client id and scopes added and authorized in G Suite.
I tried to list files in a folder in the drive using the below sample
index.php
<?php
require_once 'vendor/autoload.php';
require_once 'vendor/google/apiclient/examples/templates/base.php';
$service = get_service_document();
$folderid='FOLDER_ID';
try {
$children1 = $service->files->listFiles(array(
'q' => "'$folderid' in parents "));
$filearray1 = $children1;
}
catch(Exception $e){
echo $e->getMessage();
}
print_r($children1);
exit;
function buildServiceDrive($userEmail,$service_id,$scope,$service_filename) {
$client = new Google_Client();
putenv("GOOGLE_APPLICATION_CREDENTIALS=".$service_filename);
if ($credentials_file = checkServiceAccountCredentialsFile()) {
// set the location manually
$client->setAuthConfig($credentials_file);
}
elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
}
else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setApplicationName("DRIVE");
$client->setScopes('https://www.googleapis.com/auth/drive');
$client->setSubject($userEmail);
return new Google_Service_Drive($client);
}
//COMMON FUNCTION TO CREATE CALENDAR ID
function get_service_document(){
$userstamp='user#domain.com';
$driveService =buildServiceDrive($userstamp,'','','project-id-451a5f6b12ce.json';
return $driveService;
}
But I got this issue
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}
I m getting this issues newly created Google API Console project only
Please help me to solve this.
Thanks in advance
This is a common error when running an API call with a service account but not properly completing the domain-wide delegation (DWD) or because the authorization in the admin console has not propagated yet.
This article explains in details the process of DWD. If you have done that, wait 24 hours and it should work. If it doesn't work after that, then it must be something else but as far as I can say right now, the DWD process is the issue.
PLEASE NOTE: DWD is available only to G Suite customers. If you are using a consumer gmail.com account, you won't be able to do this. Instead, you'll have to go through the user consent OAuth flow.
This error could also occur if API client only have write permissions and in scope you specify that you only need readonly access.
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}

Can't query relation count in Parse Cloud Code afterSave method

I have an object class in Parse called Message that has a relation installations to many PFInstallation objects. I use this relation to keep track of which installations currently have local copies of each Message object.
I would like to check each time a Message object is saved whether there are a non-zero number of PFInstallations in each Message's installations relation, and to do so I am using the following method in Cloud Code:
Parse.Cloud.afterSave("Message", function(request) {
var message = request.object;
var query = message.relation("installations").query();
query.count({
success: function(count) {
console.log("count = "+count);
},
error: function(error) {
console.error("Could not count installations for Message": "+error);
}
});
});
However I am getting the following error message:
v8 after_save triggered for Message for user <redacted>:
Input: {"object":{"createdAt":"2015-08-10T18:41:21.041Z","installations":{"__type":"Relation","className":"_Installation"},"isRead":0,"objectId":"N88D2m1bqB","recipient":"recipient#domain.com","sendDate":{"__type":"Date","iso":"2015-08-10T18:40:15.047Z"},"sender":"sender#domain.com","text":"v8","updatedAt":"2015-08-10T18:41:21.041Z"}}
Result: Success
I2015-08-10T18:41:22.305Z]Could not count installations for Message: [object Object]
I have no idea why I am getting this error message or what the error [object Object] means. In other regular Cloud Code methods I have been able to count the number of objects in a relation just fine using a query like in the example above.
Please let me know what other information or clarifications I can provide to help answer this question.
You need to use the master key to read the Installation table. Try calling Parse.Cloud.useMasterKey() before running your find() query.

Error while calling google+ method plusService.People.Get

The Google+ API is set to "On" from google's developer console. I am fetching the profile information of the user by supplying the api key but I get an error saying:
Access Not Configured. Please use Google Developers Console to activate the API for your project. [403]
BaseClientService.Initializer ini = new BaseClientService.Initializer { ApiKey = "" };
PlusService plusService = new PlusService(ini);
if (plusService != null)
{
PeopleResource.GetRequest prgr = plusService.People.Get("me");
Person googleUser = prgr.Execute();
}
The error is thrown when Execute is called.
Does this service needs to be set up with "billed" profile ? This may be the reason I am getting access error.
The "me" argument only works when you have an authenticated user's OAuth 2.0 access token. Simple API access with a key only allows access to public data - try putting in a numeric user id instead of me and you should get a response.

How use Facebook Graph API to list event invitations and declined events for user

I have been trying to get list of event invitations sent to user. I played around with Graph API explorer found from
https://developers.facebook.com/tools/explorer
I have tried calling https://graph.facebook.com/userid/events but it returns me only events user has responded to as 'attending' or 'unsure'.
Is it possible to get list of event invitations for user like displayed in Facebook event page.
Also I don't know how to list events user has responded as 'declined'.
Maybe I am missing proper permission but I doubt it since I gave all event related permissions to grap explorer and still got only 'attending' or 'unsure' RSVPt events.
You can also do a GET on /{userid}/events/not_replied. It seems that Users that have not Joined the event will not show up in the /{userid}/events lists and if you look at the docs there is a subtle note there about only listing events that the user has joined. The old rest API seems to keep them in one list.
You will need to HTTP Get the following from the Graph API:
fql?q=SELECT uid,eid,rsvp_status FROM event_member WHERE uid = me()
You can get back all three statuses from that call.
{
"data": [
{
"uid": "723020003",
"eid": "19935786340002",
"rsvp_status": "not_replied"
},
{
"uid": "723020003",
"eid": "234524000290351",
"rsvp_status": "attending"
},
{
"uid": "723020003",
"eid": "210091000081240",
"rsvp_status": "declined"
}
]
}

Resources