GoogleConnect.Fetch throws Cannot pass object error
I am integrating google API into my project. I use the following code for this:
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; }
}
It runs when I click on google button and shows data in the first instance, but the second time I tried the following error.
Server error in application "/". Can't use object of type 'System.String' for input '? 1?'.
I also have a facebook and twitter button on the same screen, but I doubt this is causing the problem. Any suggestions would be helpful.
+3
source to share