I am having a very difficult time figuring out how to retrieve the Google Drive folder associated with a particular Course (ID).
My understanding is that this value is available as the teacherFolder value:
See Here:
https://developers.google.com/classroom/reference/rest/v1/courses
"id": string,
"name": string,
"section": string,
"descriptionHeading": string,
"description": string,
"room": string,
"ownerId": string,
"creationTime": string,
"updateTime": string,
"enrollmentCode": string,
"courseState": enum(CourseState),
"alternateLink": string,
"teacherGroupEmail": string,
"courseGroupEmail": string,
"teacherFolder": {
object(DriveFolder)
},
But this is returned as an object that contains:
{
"id": string,
"title": string,
"alternateLink": string,
}
I am trying to get the Google Drive folder associated with the course in Google Classroom (by Course ID) so that I can upload a resource to the appropriate folder.
Please point me in the right direction.
(I am hoping to accomplish this via php.)
Based from the documentation:
Resource: Course
{
"id": string,
"name": string,
"section": string,
"descriptionHeading": string,
"description": string,
"room": string,
"ownerId": string,
"creationTime": string,
"updateTime": string,
"enrollmentCode": string,
"courseState": enum(CourseState),
"alternateLink": string,
"teacherGroupEmail": string,
"courseGroupEmail": string,
"teacherFolder": {
object(DriveFolder)
},
"courseMaterialSets": [
{
object(CourseMaterialSet)
}
],
"guardiansEnabled": boolean,
}
You can check out the CourseMaterialSet property which hold all related marterials to the course.
CourseMaterialSet
A set of materials that appears on the "About" page of the course. These materials might include a syllabus, schedule, or other background information relating to the course as a whole.
{
"title": string,
"materials": [
{
object(CourseMaterial)
}
],
}
CourseMaterial
A material attached to a course as part of a material set.
{
// Union field material can be only one of the following:
"driveFile": {
object(DriveFile)
},
"youTubeVideo": {
object(YouTubeVideo)
},
"link": {
object(Link)
},
"form": {
object(Form)
},
// End of list of possible types for union field material.
}
Hope this helps.
Related
I am trying to use JSON Schema to validate inputs to an API. The input follows a very simple schema:
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"some_key": {
"anyOf": [
{ "type": "integer" },
{ "type": "string", "pattern": "^(0|[1-9][0-9]*)$" }
]
}
},
"required": ["some_key"],
"additionalProperties": false
}
to match documents like:
{ "some_key": 1 }
{ "some_key": "12" }
{ "some_key": 22 }
{ "some_key": 42 }
{ "some_key": "42" }
Is there a way to specify in the schema that the strings should be converted to numbers? (and fail if it is not possible)
If it is impossible to convert the strings to numbers could I convert the numbers to strings?
The actual use case will have many more properties only some of which should be converted.
I know that JSON Schema includes some features that alter the input data (like default values), but I have not found reference to such a functionality.
If it matters this will be used in a PHP program likely with opis/json-schema library.
I know that JSON Schema includes some features that alter the input data (like default values), but I have not found reference to such a functionality.
This isn't right. JSON Schema only validates what's there; it doesn't alter anything. This is probably why you haven't found a reference to this functionality.
#Byted is correct in their comment. The conversion you want needs to be done by the host application.
{
"anyOf": [
{ "type": "integer" },
{ "type": "string", "pattern": "^(0|[1-9][0-9]*)$" }
]
}
Note that this will work to validate that you get an integer or a string that represents an integer, but you're not going to be able to use other numeric validations (like minimum) on the strings.
It seems you have provided the answer yourself. In the documentation of opis/json-schema there is a link to Support for casting.
That will probably do what you need.
So what I have here is a JSON response from my PHP cURL, so I'm trying to get the specific group of array under location depending where is the identifier value I'm checking.
{
"status": "SUCCESS",
"response": {
"offset": 0,
"max": 50,
"count": 2,
"locations":[
{
"identifier":"54320",
"id": 503892,
"name":"The Foo"
},
{
"identifier":"54321",
"id": 503893,
"name":"The Bar"
}
]
}
This is what I've done so far and what I'm trying to do. So I already parse the json above and put it on foreach. Note the identifier is not always an int it can also be string.
$parsed_json = json_decode($phpCurlResponse, true);
$parsed_json = $parsed_json["response"]["locations"];
foreach($parsed_json as $key => $pj){
if($pj['identifier'] == "54320"){
echo $pj['name'].' & '.$pj['id'];//this should display The Foo & 503892
}
}
I have tried this one and it can only see the first group of array under locations but when I change the identifier value from 54321 to 112233 the response will be Identifier do not exist. can you help me how we achieve this.
Your JSON is invalid.
There shouldn't be a comma after the last object in the locations array.
There should be a } after the locations closing array bracket (]).
So is the valid JSON.
{
"status": "SUCCESS",
"response": {
"offset": 0,
"max": 50,
"count": 2,
"locations": [
{
"identifier":"54320",
"id": 503892,
"name":"The Foo"
},
{
"identifier":"54321",
"id": 503893,
"name":"The Bar"
}
]
}
}
Sorry for the premature posting but I want you to know that there's nothing wrong with the code above its just had some typo error on the json response I typed, anyways thank you for the help guys. :) So that's one possible way to get an specific set of array inside an object depending where's the key value you looking for.
How do I access webm->max in this Steam API? It's the order [{ that confuses me, array of one before object? I'm not quite sure about the targeting here..
I've tried:
$gameTrailer = $game_json->57690->data->movies[0]->webm->max;
and
$gameTrailer = $game_json['57690']['data']['movies']['webm']['max'];
The API text is like this:
"movies": [{
"id": 2029441,
"name": "Tropico 4 Gameplay Trailer",
"thumbnail": "http:\/\/cdn.akamai.steamstatic.com\/steam\/apps\/2029441\/movie.293x165.jpg?t=1447358847",
"webm": {
"480": "http:\/\/cdn.akamai.steamstatic.com\/steam\/apps\/2029441\/movie480.webm?t=1447358847",
"max": "http:\/\/cdn.akamai.steamstatic.com\/steam\/apps\/2029441\/movie_max.webm?t=1447358847"
},
"highlight": true
}],
and "movies" lies within:
{"57690": {
"data": {
Assume I'll always want the very first movie in an array (which in this case is an array of one). Thanks in advance.
Correct syntax:
$game_json->{57690}->data->movies[0]->webm->max
When you have an object with a numeric key, you have to wrap the key name by curly brackets (Numeric keys are not valid property names).
If you use the associative option:
json_decode( $data, True );
your second attempt is almost right. Simply add the correct index after movie:
$gameTrailer = $game_json['57690']['data']['movies'][0]['webm']['max'];
I have a mongoDB collection of documents. I field in the document is a Regex.
I want to take an input string from the user &
I want the Regex from the MongoDB to match the given string and echo out that resulting document.
eg:
"_id": {
"$oid": "5eeeef2a132cb8992da8"
},
"type": "integer",
"regex": "\d+",
"example": "12345"
}
If someone now inputs a string like 776847, it should go back to the collection compare the regex with the string and echo out integer, etc...
Any best methods to do this?
Thanks in advance.
If if understood you you mean that if the user input is : "1234"
and your mongo db is like :
"_id": {
"$oid": "5eeeef2a132cb8992da8"
},
"type": "integer",
"regex": "\d+",
"example": "12345"
}
The result will be integer.
you can extract all the mongo data and loop it
or
you can use mongo find method with mongodb cursor
example:
its in python but you will get the general idea
def func():
search = collection.find({'example':<user input>})
if search:
result = re.search(search['regex'],<user input>)
if result != []:
return = search['type']
else:
return "No match"
Hope it will help you
B.R
Shlomy
I have a multidimensional JSON data set that need multiple values replaced so that I can load my application to the web for some troubleshooting. The values need to be replaced because they are private records that may identify individuals' protected medical information. I suck at regex and have yet to be able to do this efficiently. What is want is to replace the following fields as described in the ():
PROV_NAME (Drlastname001, Drfirstname001 with # portion incrementing)
PAT_NAME (Patlname0001 , Patfname0001 with # portion incrementing)
PERS_ID, MRN, ENC_ID, FIN, ORD_ID (random # for each)
HOME_PHONE, CELL_PHONE (random ph #)
CMT_PRSNL (Stflastn0001 , Stffirstn0001 with # portion incrementing)
Below is a sample of the JSON dataset with the information manually replace. My real data set has multiple items for most of the arrays []. I was trying to do this in Sublime Text but once again I suck at regex. How can I do this quickly? PHP, JavaScript, within Sublime Text?
{
"TICKLER_ORDERED": {
"PROVIDER": [
{
"PROV_NAME": "Drlastname001, Drfirstname001",
"PERSON": [
{
"PERS_ID": 234213423,
"PAT_NAME": "Patlname0001 , Patfname0001",
"MRN": "45246",
"HOME_PHONE": "984-435-5673",
"CELL_PHONE": "745-547-6544",
"OLDEST_ORDER": "/Date(2012-01-03T13:34:28.000-04:00)/",
"ENCOUNTERS": [
{
"ENC_ID": 8854774,
"FIN": "78787457",
"ORDERS": [
{
"ORD_ID": 23423413,
"ORD_NAME": "MA Digital Diagnostic Mammo-Bil/CAD",
"ORD_TYPE": "Radiology",
"ORD_STATUS": "Canceled",
"ORD_PRIORITY": "Routine",
"ORD_DATE": "01/03/2012 13:34",
"DUE_DATE": "01/06/2012 13:00",
"COMMENTS": [
{
"CMT_DISP": "This is a test",
"SEQUENCE": "1",
"CMT_DTTM": "02/04/13 11:40",
"CMT_PRSNL": "Stflastn , Stffirstn"
},
{
"CMT_DISP": "This isn't a test",
"SEQUENCE": "2",
"CMT_DTTM": "02/04/13 11:42",
"CMT_PRSNL": "Stflastn0001 , Stffirstn0001"
}
]
},
{
"ORD_ID": 123234235,
"ORD_NAME": "US Breast Bilateral",
"ORD_TYPE": "Radiology",
"ORD_STATUS": "Canceled",
"ORD_PRIORITY": "Routine",
"ORD_DATE": "01/03/2012 13:34",
"DUE_DATE": "01/06/2012 14:20",
"COMMENTS": []
}
]
}
]
}
]
}
]
}
}
PHP provides great tools for iterating over an array of JSON data. As adeneo suggests, json_decode and json_encode will let you convert your data from JSON to a PHP multi-dimensional array, and back to JSON, respectively. Once you have your data in a PHP array, iterate over that array and use your knowledge of its structure, simple regular expressions (something like '/[0-9]{3}$/'), and counter variables to appropriately increase the indices.
Edited 6/2/13 for punctuation.