我已經通過api成功獲得了Google提供者的上述oauth認證的關鍵標記。從令牌c獲取用戶信息#
讓我們考慮「訪問令牌」是三十二-XXXXX-XXX-XXXXX-XXXXX其中有https://www.googleapis.com/auth/userinfo.profile
範圍現在,當我擊中訪問令牌的瀏覽器用於獲取用戶信息值有
https://www.googleapis.com/oauth2/v1/userinfo?access_token=xxxii-xxxxx-xxx-xxxxx-xxxxx;
我得到的反應是
{
"id": "XXXXXXXXXXXXXX",
"name": "XXXXXXXXXXXXXXXX",
"given_name": "XXXXXXXXXXX",
"family_name": "X",
"picture": "XXXXXXXXXX/photo.jpg",
"locale": "en"
}
我的問題是,當我救援人員到場解析上述請求唉代碼我沒有得到迴應,因爲我通過瀏覽器
的代碼,我用得到的是
String userInfo = "https://www.googleapis.com/oauth2/v1/userinfo?access_token="+token;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(userInfo);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
sr.Close();
JObject jsonResp = JObject.Parse(userInfo);
string info = "";
info += "<h3>" + jsonResp.Root["name"] + "</h3>";
info += "<img src='" + jsonResp.Root["picture"] + "' width='120'/><br/>";
info += "<br/>ID : " + jsonResp.Root["id"];
info += "<br/>Email : " + jsonResp.Root["email"];
Response.Write(info);
響應我收到空引用。
和我行
JObject jsonResp = JObject.Parse(userInfo);
了作爲
意外字符錯誤遇到在解析值:H。行1,位置1
堆棧跟蹤:
在Newtonsoft.Json.JsonTextReader.ParseValue(CHAR currentChar) 在Newtonsoft.Json.JsonTextReader.ReadInternal() 在Newtonsoft.Json。 JsonTextReader.Read() at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader) at Newtonsoft.Json.Linq.JObject.Parse(String json) at _Default.getresponse(String token)in d:\ Oauth \ WebSite3 \ Default.aspx.cs:line 99
等待您的寶貴建議和意見
你解析url'userInfo',而不是響應'sr'。 – Caramiriel 2013-03-18 07:42:04
@ Caramiriel我從nr – GowthamanSS 2013-03-18 08:35:11
得到nul迴應你可以檢查'HttpWebResponse resp'並將你的發現添加到問題中嗎?也許它返回一個HTTP 404或500狀態。 – Caramiriel 2013-03-18 09:18:05