2

I'm using Google Sheet Api for .NET. I authentificated and succesfully was sending requests untill I needed to create a spreadsheet. I read that I need to use Google Drive Api for that. So I started from Oauth. Unfortunatelly, I' getting the error

The redirect URI in the request: http://localhost:9472/authorize/ did not match a registered redirect URI.

When using this code to Authorize:

            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = Globals.GoogleClientId,
                ClientSecret = Globals.GoogleClientSecret,
            },
            new[] { DriveService.Scope.Drive },
            "My userName",
            CancellationToken.None).Result;

I don't see any params here to write my redirect_uri which I specified in Developer Console. So where should I set it? Also, it's not comfortable for user to login one time to Google Sheet service and after login again to Google Drive service. Can I set both services in one Authorization? I tried to get it by first user Auth (sheet service):

public static OAuth2Parameters GoogleParams = new OAuth2Parameters();
// ....
OAuthUtil.GetAccessToken(Globals.GoogleParams);
SpreadsheetsService service = new SpreadsheetsService("");
                service.RequestFactory = new GOAuth2RequestFactory(null, "", Globals.GoogleParams);
 DriveService driveService = new DriveService(new BaseClientService.Initializer
            {
                HttpClientInitializer = Globals.GoogleParams,
                ApplicationName = "Name",
            });

Service initializations are different, so I cannot use my GoogleParams to initialize DriveService. I guess I just don't get something, could anybody please explain me the right way to set Authorization and Create a spreadsheet. Thanks in advance!

Kara
  • 6,115
  • 16
  • 50
  • 57
Ichizy
  • 61
  • 1
  • 7
  • Probably duplicate with this one: http://stackoverflow.com/questions/12710262/google-drive-redirect-uri-mismatch?rq=1 – Dayton Wang Feb 10 '15 at 18:56

0 Answers0