You can’t get an OAuth 2.0 authorization code directly in a scheduled script because it requires a user to log in and grant consent. For automation, the usual approach is to get the code manually once and then use a refresh token, or use a server-to-server OAuth flow that doesn’t require user interaction.