Sina微博API,Oauth登录
刚写了QQ的,现在再来总结一下Sina的,不过也快忘记了,Sina的使用是在去年底了。
1.登录地址:
string consumer_key = Config.Get<string>("TSinaApi", "Key");
string consumer_secret = Config.Get<string>("TSinaApi", "Secret");
oAuthSina _oauth = new oAuthSina();
_oauth.ConsumerKey = consumer_key;
_oauth.ConsumerSecret = consumer_secret;
string authLink = _oauth.AuthorizationSinaGet() + "&oauth_callback=" + ComLib.Configuration.Config.Get<string>("Application", "oauth_callback");
//保存TokenSecret到数据库
ApiToken atk = new ApiToken() { user_id = 0, Token = _oauth.Token, TokenSecret = _oauth.TokenSecret, Verifier = "" };
atk.Create();
2.oauth_callback到Auth.ashx
string consumer_key = Config.Get<string>("TSinaApi", "Key");
string consumer_secret = Config.Get<string>("TSinaApi", "Secret");
oAuthSina _oauth = new oAuthSina();
_oauth.ConsumerKey = consumer_key;
_oauth.ConsumerSecret = consumer_secret;
_oauth.TokenSecret = atk.TokenSecret;
_oauth.Token = context.Request["oauth_token"];
_oauth.Verifier = context.Request["oauth_verifier"];
long user_id = _oauth.AccessTokenGet(_oauth.Token);
if (user_id > 0)
{
atk.Verifier = _oauth.Verifier;
atk.user_id = user_id;
//记录下 _oauth.Token 与 _oauth.TokenSecret 就OK
atk.Token = _oauth.Token;
atk.TokenSecret = _oauth.TokenSecret;
}
sdk是从sina上下载修改的,原来有地方有问题。具体是什么地方也忘记了。 没找到上传文件的地方呢。
浙公网安备 33010602011771号