I need to upload file in Google Drive using g-suite. I am getting a "Authorization Error" error like this:
The redirect URI in the request, http://127.0.0.1:62990/authorize/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/832895456388-gi5bqd65lnfk116es7lp3coes2o724s4.apps.googleusercontent.com?project=832895456388
This is detail of my Keys:
And here is code:
public ActionResult UploadFiles()
{
GSuiteCredentials gSuiteCredentials = new GSuiteCredentials();
string serverPath = Server.MapPath("/Content/Gsuite/");
string UserPath = Server.MapPath("/Content/Gsuite/67/client_secret_352975997152-cs82i5rbhe50b7n2m0bk2gut8dlm9sq4.apps.googleusercontent.com.json");
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = gSuiteCredentials.GetCredentials(serverPath, UserPath, "781"),
});
string uname = Request["uploadername"];
HttpFileCollectionBase files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFileBase file = files[i];
string fname;
// Checking for Internet Explorer
if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];}
else{fname = file.FileName;}
string fname1 = fname;
fname = Path.Combine(Server.MapPath("~/Uploads/"), fname);
file.SaveAs(fname);
gSuiteCredentials.UploadAdvance(Path.Combine(Server.MapPath("~/Uploads/"+ fname1)), service);
}
return Json("Hi, " + uname + ". Your files uploaded successfully", JsonRequestBehavior.AllowGet);
}
API's keys