Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Google Data API Authorization Redirect URI Mismatch

$
0
0

Background

I am wanting to write a small, personal web app in .NET Core 1.1 to interact with YouTube and make some things easier for me to do and I am following the tutorials/samples in Google's YouTube documentation. Sounds simple enough, right? ;)

Authenticating with Google's APIs seems impossible! I have done the following:

  1. Created an account in the Google Developer Console
  2. Created a new project in the Google Developer Console
  3. Created a Web Application OAuth Client ID and added my Web App debug URI to the list of approved redirect URIs
  4. Saved the json file provided after generating the OAuth Client ID to my system
  5. In my application, my debug server url is set (and when my application launches in debug, it's using the url I set which is http://127.0.0.1:60077).

However, when I attempt to authenticate with Google's APIs, I recieve the following error:

  1. That’s an error.

Error: redirect_uri_mismatch

The redirect URI in the request, http://127.0.0.1:63354/authorize/, does not match the ones authorized for the OAuth client.

Problem

So now, for the problem. The only thing I can find when searching for a solution for this is people that say

just put the redirect URI in your approved redirect URIs

Unfortunately, the issue is that every single time my code attempts to authenticate with Google's APIs, the redirect URI it is using changes (the port changes even though I set a static port in the project's properties). I cannot seem to find a way to get it to use a static port. Any help or information would be awesome!

NOTE: Please don't say things like "why don't you just do it this other way that doesn't answer your question at all".

The code

client_id.json

{"web": {"client_id": "[MY_CLIENT_ID]","project_id": "[MY_PROJECT_ID]","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_secret": "[MY_CLIENT_SECRET]","redirect_uris": ["http://127.0.0.1:60077/authorize/"        ]    }}

Method That Is Attempting to Use API

public async Task<IActionResult> Test(){    string ClientIdPath = @"C:\Path\To\My\client_id.json";    UserCredential credential;    using (var stream = new FileStream(ClientIdPath, FileMode.Open, FileAccess.Read))    {        credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(            GoogleClientSecrets.Load(stream).Secrets,            new[] { YouTubeService.Scope.YoutubeReadonly },"user",            CancellationToken.None,            new FileDataStore(this.GetType().ToString())        );    }    var youtubeService = new YouTubeService(new BaseClientService.Initializer()    {        HttpClientInitializer = credential,        ApplicationName = this.GetType().ToString()    });    var channelsListRequest = youtubeService.Channels.List("contentDetails");    channelsListRequest.Mine = true;    // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.    var channelsListResponse = await channelsListRequest.ExecuteAsync();    return Ok(channelsListResponse);}

Project Properties

Project Properties


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>