- Language: C#
- Framework: .NET CORE 1.1.1
- Nuget: Google.Apis.YouTube.v3 1.25.0.760 and Google.Apis 1.25.0
Hi,
What I try to do
I need to get an access token (with a refresh token) to upload videos on my users YouTube accounts.
What is not working
When I request a token through Google API, it's working in localhost but not in production. In production I get redirect_uri_mismatch
error when I redirect user to Google's OAuth server.
How I try to do it
I created a console token in Google API Console because I need to retrieve an offline token (it's not possible to get an offline token if I create an Web Application token on the Google API Console).
In my code : I redirect the user to Google's OAuth server with this url :
https://accounts.google.com/o/oauth2/auth?client_id=XXXXXX.apps.googleusercontent.com&redirect_uri=MyRedirectUri&scope=https://www.googleapis.com/auth/youtube.readonly&response_type=code&access_type=offline
To make things more easy to read :
- Base URL : https://accounts.google.com/o/oauth2/auth
- client_id : myclient ID
- redirect_uri : http://localhost:43443/Account/Oauth (dév) and http://xxxxxx.azurewebsites.net/Account/Oauth (prod)
- scope : https://www.googleapis.com/auth/youtube.readonly
- response_type :code
- access_type : offline
In development, it's working. In production, it's not working (redirect_uri_mismatch
)
I also tried to change redirect_uri to urn:ietf:wg:oauth:2.0:oob
like the answer of this post said. But it's just open a page with a code to copy / paste.
PS : I notified that when I download my "client_secrets.json" from Google Console API, there is a redirect_uris
in the download file which have these values : ["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
. But in the Google API Console I can't modify this parameter.
PS2 : I don't use .NET API to request token because as the answer to this post say (and as I tried previously), getting an offline token with .NET API is not possible.
Thanks for your help
EDIT 1 : This post not answer my question because he use a "Web application token" for one shot request. In my case, I use "Console token" (called "Other" in Google API Console) where I can't set the redirections. I use "Console token" to get an offline token.