Open blonkm opened 9 years ago
Wow, that's an interesting error message. Just to confirm, this is the Me.Content = Http.ResponseText
line? I wonder if the with_attachments
is sending raw bytes that are trying to be coerced into a string (Content
) when that isn't applicable. I haven't tested file attachments with VBA-Web so that may be causing some unexpected issues.
As for it being unauthorized, I'm not sure why that would be. I assume you're setting the Authorization
header (with OAuth1Authenticator
), but it looks like the last part of the URL is the user id so maybe you're not authorized to view submissions for that user?
No that's not really how it works. The id is a student id. This response is showing me an attachment that a student uploaded with an assignment. However, according to Schoology the API should only list the attachment url, not the actual raw data of the file. Yes I am setting an Authorization header.
According to them I should get an output as follows, in which I don't see strange characters:
{
"revision" : [
{
"late" : 0,
"uid" : 13494978,
"draft" : 0,
"num_items" : 1,
"created" : 1423140892,
"revision_id" : 1,
"attachments" : {
"files" : {
"file" : [
{
"id" : 84365494,
"converted_filemime" : "application/pdf",
"filesize" : 10375,
"fid" : 417197960,
"filename" : "opdrachten.xlsx",
"timestamp" : 1423140891,
"converted_status" : "1",
"type" : "file",
"md5_checksum" : "a0d23b623804e6a5de466a38c8570220",
"title" : "opdrachten.xlsx",
"filemime" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"converted_filename" : "1423140914-opdrachten_54d3681b56f5a_54d3683554646.pdf",
"converted_download_path" : "https://api.schoology.com/v1/system/files/drop_items/m/201502/course/138687397/1423140914-opdrachten_54d3681b56f5a_54d3683554646.pdf",
"extension" : "xlsx",
"converted_extension" : "pdf",
"converted_type" : 4,
"converted_filesize" : 10471,
"converted_md5_checksum" : "e5607ecb3035dc277f68a389144b5ff7",
"download_path" : "https://api.schoology.com/v1/system/files/drop_items/m/201502/course/138687397/opdrachten_54d3681b56f5a.xlsx"
}
]
}
}
}
]
}
They asked me to test in Google Advanced Rest Client, which I am working on.
Are you using the three-legged or two-legged approach from here: https://developers.schoology.com/api-documentation/authentication?
I haven't looked, but from memory it's the two-legged. I remember just picking the easiest one. I'm not making any enterprise stuff here. I can send you the full module code if you like.
Ok, I've looked into this more and it appears to be a UTF-8 encoding issue (converting from UTF-8 to Unicode). I'm investigating a deeper fix that will work for both Windows and Mac, but in the meantime, the following should solve your issue if you're running on Windows:
' 130, Before
Me.Content = Http.ResponseText
' After
Me.Content = StrConv(Http.ResponseText, vbUnicode)
Thanks, I'll try this. I've been pestering the help desk of the API provider, so they'll be happy if this works.
I finally tried this! And... it doesn't work. The result is an error on parsing JSON.
Error parsing JSON on line 485 Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting ':'")
I tried the same url on Google Advanced Rest Client and it worked perfectly. So.... still a problem.
output from Chrome Advanced Rest Client. I can send you the full response by email if you want to investigate.
Request
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36
Authorization: OAuth realm="https://api.schoology.com/",oauth_consumer_key="<my key>",oauth_nonce="IJYCT15O3JLU5X4R",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1442698899",oauth_version="1.0",oauth_signature="dzxSvs%2Fk0Uo6JlNogc2ogzDntAA%3D"
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: nl,en-US;q=0.8,en;q=0.6
Cookie: _mkto_trk=id:601-CPX-764&token:_mch-schoology.com-1427998680152-33498; SESSb47c23a744cc684eefd1435d2faae136=bitgnf9t5aghql1km6ib0es774; _ga=GA1.2.1150994270.1427998678; _hp2_id.3557813517=2965371892482494.2561859660.0299011750
Response
Server: nginx/1.6.0
Date: Sat, 19 Sep 2015 22:30:16 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Sat, 19 Sep 2015 22:30:16 +0000
Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0
X-Schoology: API
X-Schoology-Env: deploy
X-Schoology-Server: api263v
X-Frame-Options: SAMEORIGIN
Content-Encoding: gzip
first part of response (raw)
{"revision":[{"revision_id":1,"uid":13494978,"created":1423140892,"num_items":1,"late":0,"draft":0,"attachments":{"files":{"file":[{"id":84365494,"fid":417197960,"type":"file",
I get this error on line 130 of WebResponse.CreateFromHTTP
My url is https://api.schoology.com/v1/sections/138687397/submissions/138687411/13494978?with_attachments=true
The status code is unauthorized, but I have done plenty of requests that are authorized and return valid json, just not this one.