I have a problem in ASPSnippets Google Authentication.
I get to the part where I get to select the account and it doesn't seem to go forward, it just lets me select the account but doesnt not do the login. Here is my code.
METOSOFTEntities bd = new METOSOFTEntities();
public ActionResult Index()
{
GoogleConnect.Authorize("profile", "email");
OAuthUserModel model = new OAuthUserModel();
if (Request.QueryString["error"] == "access_denied")
{
ViewBag.Message = "User has denied access.";
}
else
{
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
string json = GoogleConnect.Fetch("me", code);
GoogleProfileModel profile = new JavaScriptSerializer().Deserialize<GoogleProfileModel>(json);
model.Id = profile.Id;
model.Name = profile.DisplayName;
model.Email = profile.Emails.Find(email => email.Type == "account").Value;
}
}
Usuario us = (from u in bd.Usuario
where u.email == model.Email
select u).FirstOrDefault();
if (us == null)
{
return RedirectToAction("Edit", "Google", model);
}
else
{
FormsAuthentication.SetAuthCookie(model.Name, true);
return RedirectToAction("Index", "Home", new { });
}
}
public ActionResult Login()
{
GoogleConnect.ClientId = "335225904765-9h5aq1jss5ee66ap84crtkk13efrp7o9.apps.googleusercontent.com";
GoogleConnect.ClientSecret = "7Ezmi0sFtvkAwojFoxbD--G-";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
return RedirectToAction("Index");
}
I get an error...
Its on the string json = GoogleConnect.Fetch("me", code);
System.Exception: '{
"error": {
"code": 403,
"message": "Legacy People API has not been used in project 335225904765 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project=335225904765 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project=335225904765"
}
]
}
]
}
}