I’m working on migrating my existing PHP project that uses Google Calendar API to a new Go implementation. I followed the official Google documentation to set up the basic structure.
package main
import (
"fmt"
"google.golang.org/api/calendar/v3"
"golang.org/x/oauth2/google"
)
func main() {
credentialsFile := "credentials.json"
// Error occurs here when trying to load config
config, err := google.ConfigFromJSON(data, calendar.CalendarScope)
if err != nil {
fmt.Printf("Error loading credentials: %v", err)
}
}
When I execute my program, I encounter this error message:
Cannot parse credentials file: missing redirect URL in the oauth_credentials.json
I have an existing OAuth client that works perfectly with my PHP application. I want to reuse the same credentials for my Go version to access user calendar data. However, downloading the JSON file from Google Console gives me the error mentioned above.
I hit this exact problem converting a Laravel app to Go. Your PHP OAuth client config is missing the redirect_uris field that Go’s OAuth2 needs. Don’t bother creating new desktop credentials - just update your existing web app credentials in Google Console. Go to your OAuth 2.0 client settings and add “http://localhost:8080” and “urn:ietf:wg:oauth:2.0:oob” to the authorized redirect URIs. Download the updated JSON file. Now you can use the same client ID for both apps. You’ll still need to fix that undefined data variable though - use ioutil.ReadFile to read the credentials file before passing it to ConfigFromJSON.
check your oauth client setup in google console - you probably created it as ‘web application’ instead of ‘desktop app’. that’s why redirect_uris is missing. also, your code has a data variable that isn’t defined anywhere. you need to read the file first with ioutil.ReadFile.
yeah totally! switchin to desktop app is key here. the oauth client type is super important since web apps and desktop apps have different redirect URIs. go is stricter on this. just recreate the oauth client in google console for desktop and download the new json. should work after that!
Google Calendar API auth issues are the worst when you’re on deadline. Been there - watched this exact problem kill deployments.
Everyone’s throwing manual fixes at you, but there’s a smarter way. Skip the OAuth headaches and automate the whole integration.
Had a migration project last month syncing calendar data across multiple systems. OAuth setup, token refresh, different credential types - total time sink.
Built it as an automated workflow instead. No credential files, no OAuth debugging, no manual token management. The platform handles Google API auth automatically.
You can trigger on calendar events, sync with your Go app, handle complex calendar logic. 30 minutes setup vs days debugging OAuth.
Using this for all our Google API stuff now. Way more reliable than managing credentials across environments.
This is a credential type mismatch between platforms. I faced a similar issue while migrating from PHP to Go - Google’s OAuth in Go validates redirect URIs much more strictly than other languages. Your PHP credentials are likely set up as a web application client, which lacks the redirect_uris array that desktop apps require. It’s best not to alter your existing setup. Instead, create separate OAuth credentials specifically for your Go app. In Google Cloud Console, select ‘Desktop application’ when generating new credentials; this will automatically generate the redirect_uris field with “urn:ietf:wg:oauth:2.0:oob” and “http://localhost”. Additionally, ensure you are passing a well-defined data variable to ConfigFromJSON; make sure to read the credentials file before parsing it.
Your credentials file is missing the redirect_uris field, which disrupts the OAuth2 flow in Go. To resolve this, download credentials for a ‘Desktop application’ from the Google Cloud Console, as this includes the necessary redirect URIs.