人人登陆并获取用户部分信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
namespace SinaLoginWebApp
{
public partial class renren : System.Web.UI.Page
{//应用ID:210192
//API Key:612da7618e0c4810bbcd5d128099cabc
//Secret Key:9574ab71a75240e49d9199a2584e2fbf
protected void Page_Load(object sender, EventArgs e)
{
// 1】第一次请求 login2.NavigateUrl = "https://graph.renren.com/oauth/authorize?client_id=210192&response_type=code&redirect_uri=http://yiguanshou.com/renren.aspx&display=page";
//CheckJson();
//string code = Request["code"].ToString();
string str = "u7vpoLQTe0ahpvExl6csQT7W3xL7fHoc";
string renrenToken = "https://graph.renren.com/oauth/token?client_id=210192&client_secret=9574ab71a75240e49d9199a2584e2fbf&redirect_uri=http://yiguanshou.com/renren.aspx&grant_type=authorization_code&code="+str;
string respone = WebRequest(HttpMethod.GET, renrenToken, string.Empty);
PassportRenRenOAuthInfo info=new PassportRenRenOAuthInfo();
JavaScriptSerializer js = new JavaScriptSerializer();
info = js.Deserialize<PassportRenRenOAuthInfo>(respone);
Response.Write(respone);
}
//private void CheckJson()
//{
// string str='{"expires_in":2594996,"refresh_token":"210192|0.HwM8MGaXzLY1LHrhdKhOwSEs6XdW8tH2.246701167.1346415003415","user":{"id":246701167,"name":"宋波","avatar":[{"type":"avatar","url":"http://hdn.xnimg.cn/photos/hdn521/20110312/1555/h_head_BxVD_27af0001cd052f75.jpg"},{"type":"tiny","url":"http://hdn.xnimg.cn/photos/hdn221/20110312/1555/tiny_LP13_294099o019118.jpg"},{"type":"main","url":"http://hdn.xnimg.cn/photos/hdn521/20110312/1555/h_main_sKL0_27af0001cd052f75.jpg"},{"type":"large","url":"http://hdn.xnimg.cn/photos/hdn521/20110312/1555/h_large_94UP_27af0001cd052f75.jpg"}]},"access_token":"210192|6.05852f65d6fb266f62a418328a7e7c72.2592000.1349010000-246701167"}';
//}
private enum HttpMethod { GET, POST };
private string WebRequest(HttpMethod method, string url, string postData)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
//if (ParamHelper.OpenWebProxy &&
// StringUtils.IsNullOrEmpty(ParamHelper.WebProxyInfo) == false)
//{
// string[] webProxyInfo = ParamHelper.WebProxyInfo.Split('|');
// webRequest.Proxy = new WebProxy(webProxyInfo[0]);
// webRequest.Proxy.Credentials = new NetworkCredential(webProxyInfo[1], webProxyInfo[2]);
//}
///写入数据
if (method == HttpMethod.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
catch (Exception ex)
{
}
finally
{
if (requestWriter != null)
{
requestWriter.Close();
requestWriter = null;
}
}
}
///读取数据
StreamReader responseReader = null;
try
{
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
}
catch (Exception ex)
{
}
finally
{
if (webRequest != null &&
webRequest.GetResponse() != null &&
webRequest.GetResponse().GetResponseStream() != null)
{
webRequest.GetResponse().GetResponseStream().Close();
}
if (responseReader != null)
{
responseReader.Close();
responseReader = null;
}
webRequest = null;
}
return responseData;
}
}
public class PassportRenRenOAuthInfo
{
public PassportRenRenOAuthInfo() { }
private string expires_in;
private string refresh_token;
private User user;
private string access_token;
public string Expires_in
{
get { return expires_in; }
set { expires_in = value; }
}
public string Refresh_token
{
get { return refresh_token; }
set { refresh_token = value; }
}
public string Access_token
{
get { return access_token; }
set { access_token = value; }
}
public User User
{
get { return user; }
set { user = value; }
}
}
public class User
{
public User() { }
private string id;
private string name;
private List<Avatar> avatar;
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public List<Avatar> Avatar
{
get { return avatar; }
set { avatar = value; }
}
}
public class Avatar
{
public Avatar() { }
private string type;
private string url;
public string Type
{
get { return type; }
set { type = value; }
}
public string Url
{
get { return url; }
set { url = value; }
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
namespace SinaLoginWebApp
{
public partial class renren : System.Web.UI.Page
{//应用ID:210192
//API Key:612da7618e0c4810bbcd5d128099cabc
//Secret Key:9574ab71a75240e49d9199a2584e2fbf
protected void Page_Load(object sender, EventArgs e)
{
// 1】第一次请求 login2.NavigateUrl = "https://graph.renren.com/oauth/authorize?client_id=210192&response_type=code&redirect_uri=http://yiguanshou.com/renren.aspx&display=page";
//CheckJson();
//string code = Request["code"].ToString();
string str = "u7vpoLQTe0ahpvExl6csQT7W3xL7fHoc";
string renrenToken = "https://graph.renren.com/oauth/token?client_id=210192&client_secret=9574ab71a75240e49d9199a2584e2fbf&redirect_uri=http://yiguanshou.com/renren.aspx&grant_type=authorization_code&code="+str;
string respone = WebRequest(HttpMethod.GET, renrenToken, string.Empty);
PassportRenRenOAuthInfo info=new PassportRenRenOAuthInfo();
JavaScriptSerializer js = new JavaScriptSerializer();
info = js.Deserialize<PassportRenRenOAuthInfo>(respone);
Response.Write(respone);
}
//private void CheckJson()
//{
// string str='{"expires_in":2594996,"refresh_token":"210192|0.HwM8MGaXzLY1LHrhdKhOwSEs6XdW8tH2.246701167.1346415003415","user":{"id":246701167,"name":"宋波","avatar":[{"type":"avatar","url":"http://hdn.xnimg.cn/photos/hdn521/20110312/1555/h_head_BxVD_27af0001cd052f75.jpg"},{"type":"tiny","url":"http://hdn.xnimg.cn/photos/hdn221/20110312/1555/tiny_LP13_294099o019118.jpg"},{"type":"main","url":"http://hdn.xnimg.cn/photos/hdn521/20110312/1555/h_main_sKL0_27af0001cd052f75.jpg"},{"type":"large","url":"http://hdn.xnimg.cn/photos/hdn521/20110312/1555/h_large_94UP_27af0001cd052f75.jpg"}]},"access_token":"210192|6.05852f65d6fb266f62a418328a7e7c72.2592000.1349010000-246701167"}';
//}
private enum HttpMethod { GET, POST };
private string WebRequest(HttpMethod method, string url, string postData)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
//if (ParamHelper.OpenWebProxy &&
// StringUtils.IsNullOrEmpty(ParamHelper.WebProxyInfo) == false)
//{
// string[] webProxyInfo = ParamHelper.WebProxyInfo.Split('|');
// webRequest.Proxy = new WebProxy(webProxyInfo[0]);
// webRequest.Proxy.Credentials = new NetworkCredential(webProxyInfo[1], webProxyInfo[2]);
//}
///写入数据
if (method == HttpMethod.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
catch (Exception ex)
{
}
finally
{
if (requestWriter != null)
{
requestWriter.Close();
requestWriter = null;
}
}
}
///读取数据
StreamReader responseReader = null;
try
{
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
}
catch (Exception ex)
{
}
finally
{
if (webRequest != null &&
webRequest.GetResponse() != null &&
webRequest.GetResponse().GetResponseStream() != null)
{
webRequest.GetResponse().GetResponseStream().Close();
}
if (responseReader != null)
{
responseReader.Close();
responseReader = null;
}
webRequest = null;
}
return responseData;
}
}
public class PassportRenRenOAuthInfo
{
public PassportRenRenOAuthInfo() { }
private string expires_in;
private string refresh_token;
private User user;
private string access_token;
public string Expires_in
{
get { return expires_in; }
set { expires_in = value; }
}
public string Refresh_token
{
get { return refresh_token; }
set { refresh_token = value; }
}
public string Access_token
{
get { return access_token; }
set { access_token = value; }
}
public User User
{
get { return user; }
set { user = value; }
}
}
public class User
{
public User() { }
private string id;
private string name;
private List<Avatar> avatar;
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public List<Avatar> Avatar
{
get { return avatar; }
set { avatar = value; }
}
}
public class Avatar
{
public Avatar() { }
private string type;
private string url;
public string Type
{
get { return type; }
set { type = value; }
}
public string Url
{
get { return url; }
set { url = value; }
}
}
}
作者:Bober Song
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。