c# - 无法将“System.String”类型的对象转换为“?2?.?3?.?5?”类型
问题描述
从我的 ASP.NET 网页调用 Google 登录时,我遇到了这个错误。
这是我在执行代码时遇到的错误。
System.InvalidOperationException: Cannot convert object of type 'System.String' to type '?2?.?3?.?5?'
我正在使用带有 C# 的 ASP.NET 将 Google 登录集成到我的网页。
我的代码如下:
page_load() {
GoogleConnect.ClientId = "xxxxxxxx.apps.googleusercontent.com";
GoogleConnect.ClientSecret = "xxxxxxxxxx";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"];
string json = GoogleConnect.Fetch("me", "code");
GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
Label1.Text = profile.Id;
Label2.Text = profile.DisplayName;
Label3.Text = profile.Emails.Find(email => email.Type == "account").Value;
Image1.ImageUrl = profile.Image.Url;
Button1.Visible = false;
}
if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
GoogleConnect.Authorize("profile", "email");
}
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; }
}
}
解决方案
推荐阅读
- c - 非常简单的多数组c程序 - 问题noob
- c++ - 试图理解 C++ 代码,读取文件
- python - 如何搜索列列表以找到特定的正则表达式模式,并根据该值创建新列?
- node.js - 安装所需的最新版本的 npm
- python - 使用 python 在 AWS Lambda 中将大型 CSV 转换为 JSON
- google-chrome-extension - 为什么 URL 重定向权限在 Chrome Manifest v2 中有效,但在 v3 中无效?
- r - DT 中的因子搜索清除按钮:shinydashboard 与 shinymaterial
- python - 图像旋转在这个函数中是如何工作的
- python - 刮python:现有连接被远程主机强行关闭
- vue.js - Tableau Vuejs getWorkBook()“无法读取 null 的属性 get_workbook”