Home > Software design >  Google Classroom API | How add scopes in HTTP request
Google Classroom API | How add scopes in HTTP request

Time:10-28

I want to get a list of courses from an audience by HTTP request, I have set the required areas in the project in Google Cloud, but I still get an error when I try to get the courses.

P.S - Please do not offer me documentation and libraries, do not try to convince me, I just need an HTTP request.

{
    "error": {
        "code": 403,
        "message": "Request had insufficient authentication scopes.",
        "status": "PERMISSION_DENIED",
        "details": [{
            "@type": "type.googleapis.com/google.rpc.ErrorInfo",
            "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
            "domain": "googleapis.com",
            "metadata": {
                "method": "google.classroom.v1.Courses.ListCourses",
                "service": "classroom.googleapis.com"
            }
        }]
    }
}

I tried adding ?scope=https://www.googleapis.com/auth/classroom.courses.readonly to the end of the link Here is the request template

curl \
  'https://classroom.googleapis.com/v1/courses?key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

CodePudding user response:

Im going to assume that you are using enter image description here

So in your case the error Request had insufficient authentication scopes. means that when you requested authorization you did not request one of the scopes above. There for your access token has insufficient authorization scopes to make the request.

The solution is to reauthorize your user with one of the scopes required by the method in question.

You can read more about how to request authorization and what scopes are in the Using OAuth 2.0 to Access Google APIs documentation page.

Hint: Your very first in the oauth2 flow contains the scope.

https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/classroom.courses& response_type=code&redirect_uri=http://127.0.0.1:9004&client_id=client_id

This video may help you understand scopes Understanding Google OAuth 2.0 with curl since you appear to be using curl and not just raw HTTP calls.

  • Related