Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classroom snippets #66

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion classroom/snippets/createCourse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"fmt"
"golang.org/x/oauth2/google"
"log"
"net/http"

Expand Down Expand Up @@ -46,6 +47,19 @@ func createCourse(client *http.Client) {
if err != nil {
log.Fatalf("Course unable to be created %v", err)
}
// [END classroom_create_course]
fmt.Printf("Created course: %v", course.Id)
// [END classroom_create_course]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per earlier guidance on snippets, expand the area in the region tags to include imports & auth.

}
func main() {
ctx := context.Background()
/* Load pre-authorized user credentials from the environment.
TODO(developer) - See https://developers.google.com/identity and
https://cloud.google.com/docs/authentication/production for
guides on implementing OAuth2 for your application.
*/
client, err := google.DefaultClient(ctx, classroom.ClassroomCoursesScope)
if err != nil {
log.Fatalf("Failed Default authentication: %v", err)
}
createCourse(client)
}
20 changes: 9 additions & 11 deletions classroom/snippets/getCourse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"log"
"net/http"

Expand All @@ -40,21 +39,20 @@ func getCourse(client *http.Client) {
if err != nil {
log.Fatalf("Course unable to be retrieved %v", err)
}
// [END classroom_get_course]
fmt.Printf("Course with ID %v found.", course.Id)
// [END classroom_get_course]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other file -- expand region tags to include imports & auth

}

func main() {
b, err := ioutil.ReadFile("credentials.json")
if err != nil {
log.Fatalf("Unable to read client secret file: %v", err)
}

// If modifying these scopes, delete your previously saved token.json.
config, err := google.ConfigFromJSON(b, classroom.ClassroomCoursesScope)
ctx := context.Background()
/* Load pre-authorized user credentials from the environment.
TODO(developer) - See https://developers.google.com/identity and
https://cloud.google.com/docs/authentication/production for
guides on implementing OAuth2 for your application.
*/
client, err := google.DefaultClient(ctx, classroom.ClassroomCoursesScope)
if err != nil {
log.Fatalf("Unable to parse client secret file to config: %v", err)
log.Fatalf("Failed Default authentication: %v", err)
}
client := getClient(config)
getCourse(client)
}
64 changes: 0 additions & 64 deletions classroom/snippets/oauth.go

This file was deleted.