How to obtain data from Canvas API? - canvas-lms

I want to obtain data through canvas API from a moodle course that our institute is doing right now. I went through the documentation and I have generated an access token as advised in the API documentation. But now I don't know how to proceed.
I tried different examples in the chrome browser console.
ex: GET https:///login/oauth2/auth? client_id=XXX&response_type=code&redirect_uri=https://example.com/oauth_complete&state=YYY
But it didn't provide me any result. Instead I got errors such as "Uncaught SyntaxError: Unexpected identifier".
Can someone please tell me where should I start?
Thanks a lot.

You can generate an Access Token by going to "Account -> Settings -> New Access Token" Then copy down the access token.
Then you can make api calls by either
Attaching that access token to your request as a header curl -H "Authorization: Bearer <token>" 'http://<canvas>/api/v1/accounts/<account_id>/courses
or
Attaching the access token as a GET query parameter
http://<canvas>/api/v1/accounts/<account_id>/courses?access_token=token_of_magical_powers
Beware that the access token has all of the same privileges as the user for whom it was generated, so keep it guarded.
More documentation and examples can be found in the canvas community pages.

Related

Google maps street view publish

What is the procedure to follow for google street view publish. Is google cloud service required?
When I tried, is returned me status Unauthorized
I tried to find an answer here already, on StackOverflow, but all are not clear. Please guide me.
This error means that the your access token is missing or incorrect. Make sure the http header contains a valid token like
authorization: Bearer YOUR_ACCESS_TOKEN
You can find out more in Google's OAuth2 documentation:
https://developers.google.com/identity/protocols/OAuth2

Google Drive API downloadURL 401 error

Anybody can help or enlighten me with my issue:
I'm a Java developer and I have an existing smart printer app called GDrive App. It uses Google Drive API (oauth 2.0, gdata-version 2.0 and 3.0 for download-print file) .
This has been working for months until now. Actually, only the download-printing part is no longer working this time, I can still access the app (retrieve files, create folder, search and delete files).
Actual problem:
I keep on getting 401 error when I try to download file (to input stream) for printing. It's confusing because I already provided all the necessary information during the request. And it has been working for many months. No changes of the code. Weird.
I have this for headers:
[Authorization: Bearer ya29.CjAkA8uPBUsKWYMSEDpPxUbP_vtQJOKfCZ7O8I4GkpUkN70bGgnDTAVYiVW2m353H2Y
, GData-Version: 3.0
]
While executing this URL to download and print resource, I couldn't access this.
https://doc-0o-7o-docs.googleusercontent.com/docs/securesc/l9c2gms12ko7qqfc58putbb2v38kkvmm/dp5l9kmpu48kdi8mp2rvtmc1dm1f41tk/1468828800000/09859633411849852329/09859633411849852329/0ByU-nFK_03gtZGhBZkxCYmExeGc?e=download&gd=true
Error 401 means that you aren't authorized properly. Most likely the ya29.CjAkA8uPBUsKWYMSEDpPxUbP_vtQJOKfCZ7O8I4GkpUkN70bGgnDTAVYiVW2m353H2Y access token you are using expired and you have to request another.
You should write your code to anticipate the possibility that a granted token might no longer work. A token might stop working for one of these reasons:
The user has revoked access.
The token has not been used for six months.
The user changed passwords and the token contains Gmail, Calendar,
Contacts, or Hangouts scopes.
The user account has exceeded a certain number of token requests.
source
You can use GoogleAuthorizationCodeTokenRequest to request an access token and possibly a refresh token.

Box API get shared file results in 404

Already looked at How to use box-api to get the Shared item? and Box Developers documentation https://developers.box.com/docs/#shared-items. I have tried doing a request to https://api.box.com/2.0/shared_items in .NET code, in Firefox Poster and using curl. They all resulted in 404. I have verified that my file's shared link is open to anyone with a link. Here's my curl code (sanitized):
curl https://api.box.com/2.0/shared_items -H "Authorization: Bo
xAuth api_key=xxxxxxxxxxxxxxxxxxxxx" -H "BoxApi: shared_link=https://
app.box.com/s/yyyyyyyyyyyyyyyyyyyyyyyyyyyy"
{"type":"error","status":404,"code":"not_found","help_url":"http:\/\/developers.
box.com\/docs\/#errors","message":"Not Found","request_id":"196207167555469c3017
14b"}
What might be the problem? I tried a wrong api_key and got back 401 so I know the whole setup is correct.
Your API key shouldn't be included anywhere in the request. I believe that form of authorization was used in the old v1 API and is now deprecated. There's a cURL example in the docs you linked to that shows what your authorization header should look like:
curl https://api.box.com/2.0/shared_items
-H "Authorization: Bearer ACCESS_CODE"
-H "BoxApi: shared_link=SHARED_LINK"
For more info on how to obtain the access token that goes into the authorization header, take a look at the OAuth tutorial.
The reason why authentication is required is because the API will return info about the item within the context of the caller's permissions. For example, if the creator of the shared link makes the API call, then private information (such as the item's full path within their account) will be returned. If another user makes the call, then that private information will be omitted.
That being said, you're still able to anonymously download an open shared link by navigating to it directly. You only need to use the API if you want more information about the item that the link points to.

how to call rest api for sandbox paypal for payment verification

Hi am running paypal sample application it runs perfetct (Version 2.0 paypal sdk)
i used my sandbox client id in application
after successfulle payment it gives me json output
but i want to confirm that payment am confused how i can confirm it
i got some docs where they mention to use REST api of sandbox paypal and chek with it
but i dont know how to do it
below is the link
my problem is i dont know how to call below api on browser i have access token and payment id
https://api.sandbox.paypal.com/v1/payments/payment/PAYMENT ID\
-H "Content-Type: application/json" \
-H "Authorization: Bearer {accessToken}"
when am trying to run it as it is on browser with my input parameter it shows me
{"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"https://api.sandbox.paypal.com/docs/api/#INTERNAL_SERVICE_ERROR"}
this message please help me out please
Dave from PayPal here.
Sometimes we see that INTERNAL_SERVICE_ERROR when you have made a payment using the same PayPal account for both payer and payee.
And sometimes INTERNAL_SERVICE_ERROR means that the Sandbox server is having a transient problem, in which case trying again after some time has passed will solve the problem.
Might either of these scenarios apply in your case?

Getting the user id for a given token

I'm using box API v2 and successfully with OAuth2. I'm successfully getting the access token back, but in order to avoid the "confused deputy problem" I need to have a way of getting the user id that a given access token relates to.
Is there a way of doing this? I'm trying to use the /tokens endpoint without luck. I read that you need to enable that but I can't find how. Even if I managed to enable it, would that help?
Thanks!
the /users/me endpoint will tell you the user id (and other info) associated with the access token that was used to authenticate the request. Documentation here.