我正在将 Google API 集成到我的项目中。我正在使用以下代码来执行此操作:
public void google()
{
GoogleConnect.ClientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
GoogleConnect.ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"].ToString();
string json = GoogleConnect.Fetch("me", code.ToString());
GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
//code for showing data on my page
}
if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
}
public class GoogleProfile
{
public string Id { get; set; }
public string DisplayName { get; set; }
public Image Image { get; set; }
public List<Email> Emails { get; set; }
public string Gender { get; set; }
public string ObjectType { get; set; }
}
public class Email
{
public string Value { get; set; }
public string Type { get; set; }
}
public class Image
{
public string Url { get; set; }
}
当我单击谷歌按钮时它会运行并在第一个实例上显示数据,但在我第二次尝试时它会抛出以下错误。
“/”应用程序中的服务器错误。无法转换类型的对象
“System.String”以键入“?1?”。
我在同一屏幕上还有一个 facebook 和 twitter 按钮,但我怀疑它是导致问题的原因。任何建议都会有帮助。
我已经使用了这个 api,你应该使用它,在显示个人资料的地方放置一个清晰的按钮创建按钮清除
protected void Clear(object sender, EventArgs e)
{
GoogleConnect.Clear();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)