package main
import (
"context"
"fmt"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"net/http"
"log"
"io/ioutil"
)
func main() {
ctx := context.Background()
// Replace with your Google client ID and client secret
config := &oauth2.Config{
ClientID: "YOUR_CLIENT_ID",
ClientSecret: "YOUR_CLIENT_SECRET",
RedirectURL: "YOUR_REDIRECT_URL",
Endpoint: google.Endpoint,
Scopes: []string{"https://www.googleapis.com/auth/userinfo.profile"},
}
// Generate a URL to redirect user to authorize
url := config.AuthCodeURL("state-token", oauth2.AccessTypeOffline)
fmt.Println("Visit the URL for the auth dialog:", url)
// Once you get the authorization code, exchange it for an access token
var code string
fmt.Print("Enter the authorization code: ")
fmt.Scan(&code)
token, err := config.Exchange(ctx, code)
if err != nil {
log.Fatal(err)
}
client := config.Client(ctx, token)
// Make a request to Google APIs with the authorized client
resp, err := client.Get("https://www.googleapis.com/userinfo/v2/me")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println("Response from Google API:", string(body))
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?