求QQ微博登录和发微博的C#代码

stonepeter 2010-12-18 10:50:47
求QQ微博登录和发微博的C#代码。
要写一个QQ微博的桌面应用程序,尤其是不知道怎么写微博用户登录的代码。今天CSDN的搜索又坏了。
...全文
2051 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
君子兰龙 2011-04-07
  • 打赏
  • 举报
回复
[Quote=引用 35 楼 stonepeter 的回复:]

绝望中我完成了第一步,谢谢新浪的帮助文档。
我把callback函数改成了oob
就获得了正确的返回了。^_^

7e
oauth_token=63350698757247848ad56c330c01f915&oauth_token_secret=83d98dbadb45c803063205baecd11c3d&oauth_callback_confirmed=true……
[/Quote]
看看我的程序带该如下:
public static String set_basestring() throws UnsupportedEncodingException {
String bss;
bss = "GET" + "&" + URLEncoder.encode(CONST.REQUEST_URL, "utf-8") + "&";

// bss = URLEncoder.encode(bss, "utf-8");
Log.e("OAUTH", "oauth_signature - Base1" + bss);
String bsss = "oauth_callback=" + "www.qq.com" + "&oauth_consumer_key="
+ CONST.APP_KEY + "&oauth_nonce=" + createRondomString()
+ "&oauth_signature_method=" + "HMAC-SHA1"
+ "&oauth_timestamp=" + createTimeStamp() + "&oauth_version="
+ "1.0";
bsss = URLEncoder.encode(bsss, "utf-8");
Log.e("OAUTH", "oauth_signature - Base2" + bsss);
return bss + bsss;
}

/**
*
* @param data
* @param key
* get oauth_signature
* @return
*/
public static String hmacsha1(String data, String key) {
byte[] b = HMACSHA1.getHmacSHA1(data, key);
String s = new BASE64Enconder().encode(b);
return s;}
君子兰龙 2011-04-07
  • 打赏
  • 举报
回复
[Quote=引用 34 楼 stonepeter 的回复:]

引用 33 楼 stonepeter 的回复:
引用 31 楼 a82344626 的回复:
抓包
先登陆包这个比较简单 网上已有这个的算法了

是这发信息的包
http://t.qq.com/publish.php
content=内容&countType=&pic&viewModel=
很简单的问题
自……
[/Quote]
我最近也想做腾讯的微博,总是出现401错误,请帮忙了
生成URL:https://open.t.qq.com/cgi-bin/request_token?oauth_nonce=4tocg4y9u4p1v61ggk77d4hnoh6y20b8&oauth_signature=uDi7vBa0PJ7mIt107BSnt0Sghr0=&oauth_callback=www.qq.com&oauth_consumer_key=f14c1912e591496fa00671288817f418&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1302157322&oauth_version=1.0
上面的callback是我申请应用的时候填写的地址
stonepeter 2010-12-21
  • 打赏
  • 举报
回复
绝望中我完成了第一步,谢谢新浪的帮助文档。
我把callback函数改成了oob
就获得了正确的返回了。^_^

7e
oauth_token=63350698757247848ad56c330c01f915&oauth_token_secret=83d98dbadb45c803063205baecd11c3d&oauth_callback_confirmed=true
0
stonepeter 2010-12-20
  • 打赏
  • 举报
回复
[Quote=引用 33 楼 stonepeter 的回复:]
引用 31 楼 a82344626 的回复:
抓包
先登陆包这个比较简单 网上已有这个的算法了

是这发信息的包
http://t.qq.com/publish.php
content=内容&countType=&pic&viewModel=
很简单的问题
自己多上上baidu找找~
数据抓最是怎么做的

很好的提醒。感谢感谢!……
[/Quote]

Fiddler2 获得了更明确的错误信息。。。

12
Invalid signature

0

无效的签名。

"1.获取未授权的Request Token

本步骤用于签名的secret是AppKey Secret"

不太明白这句话。。。

参考新浪的签名-不知道算法哪错了。。。如果签名的方法错了,抓包分析也没用:(
string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);

HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));
return GenerateSignatureUsingHash(signatureBase, hmacsha1);

stonepeter 2010-12-20
  • 打赏
  • 举报
回复
虽然我仍然在研究,但仍然期待有做过的朋友能给更多示例代码。
stonepeter 2010-12-20
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 a82344626 的回复:]
抓包
先登陆包这个比较简单 网上已有这个的算法了

是这发信息的包
http://t.qq.com/publish.php
content=内容&countType=&pic&viewModel=
很简单的问题
自己多上上baidu找找~
数据抓最是怎么做的
[/Quote]
很好的提醒。感谢感谢!今天我在车上就这么想过。。。
a82344626 2010-12-20
  • 打赏
  • 举报
回复
抓包
先登陆包这个比较简单 网上已有这个的算法了

是这发信息的包
http://t.qq.com/publish.php
content=内容&countType=&pic&viewModel=
很简单的问题
自己多上上baidu找找~
数据抓最是怎么做的
stonepeter 2010-12-20
  • 打赏
  • 举报
回复
按QQ的格式要求,生成了一个请求,但得到了401未授权错误。晕啊。
https://open.t.qq.com/cgi-bin/request_token?oauth_callback=http://qunmgr.qq.com/authapi/callback.php&oauth_consumer_key=fb76ef232d6841e19f48428c12f36893&oauth_nonce=6915173b82c14b7d93c254fdc72910ba&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1292837077&oauth_version=1.0&oauth_signature=UKhR%2fsAx5PU3nD8UaSLkLJnmc9Q%3d
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yangquanlaohou 的回复:]
看看腾讯微博开发者平台
[/Quote]
看了。上面是关于网页开发的内容。也下载了一些共开的代码,但没能回答我的问题。
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 woxiaode7 的回复:]
有国外代理吗
[/Quote]这个有关系么?可以有国外代理。VPN也有。
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 dfhdhq 的回复:]
http://www.cnblogs.com/cmt/archive/2010/05/13/1733904.html
供参考,我觉得有点类似,虽然我的领域没涉及过这些。。。。
[/Quote]
谢谢楼上。这个应当对我有用。我仔细研究研究。
weakey 2010-12-19
  • 打赏
  • 举报
回复
http://www.cnblogs.com/cmt/archive/2010/05/13/1733904.html
供参考,我觉得有点类似,虽然我的领域没涉及过这些。。。。
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
重要信息:)OAuth中文版
http://163navy.blog.163.com/blog/static/105304086201042762510130/
TOC
Appendix A.3. Requesting User Authorization
The Consumer redirects Jane's browser to the Service Provider User Authorization URL to obtain Jane's approval for accessing her private photos.

http://photos.example.net/authorize?oauth_token=hh5s93j4hdidpola&oauth_callback=http%3A%2F%2Fprinter.example.com%2Frequest_token_ready


The Service Provider asks Jane to sign-in using her username and password and, if successful, asks her if she approves granting printer.example.com access to her private photos. If Jane approves the request, the Service Provider redirects her back to the Consumer's callback URL:

http://printer.example.com/request_token_ready?oauth_token=hh5s93j4hdidpola



stonepeter 2010-12-19
  • 打赏
  • 举报
回复
oh
这里对认证过程又说了一次
http://open.t.qq.com/resource.php?i=1,2

腾讯微博API通过以下四个步骤来完成认证授权并访问或修改受限资源的流程

1.获取未授权的Request Token(temporary credentials)
2.请求用户授权Request Token
3.使用授权后的Request Token换取Access Token(token credentials)
4.使用 Access Token 访问或修改受保护资源

依然没有提到QQ号和密码。
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
谢谢帮顶贴的朋友。

/*
* http://open.t.qq.com/resource.php?i=1,1
* 上面说明OAuth分几步走
* request_token - to request unauthed request_Token
* user authed request_token
* 然后是交换access_token
* 所有过程中都是提交的oauth相关的数据,没有一处提到QQ号和密码。
* */

我对OAuth了解相当少。只知道web form数据可以用POST方式提交,我看http://t.qq.com页面代码里就是用POST方式提交的。
lanye31678 2010-12-19
  • 打赏
  • 举报
回复
http://open.t.qq.com/resource.php?i=1,1
skysky000 2010-12-19
  • 打赏
  • 举报
回复
友情帮顶。。。
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
我看http://t.qq.com 网页上的登录页面没能明白数据是怎么提交的。
路漫漫啊。。。。
stonepeter 2010-12-19
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 sp1234 的回复:]
不同的协议可能完全是两回事。

如果要求低级的网站管理用户的登录名和密码,那么失去保守秘密的。所谓OAuth那种,就是让低级的网站根本拿不到用户的登录信息,你只是在高级网站上拿到一个自己的授权号码,然后你要乖乖地把用户重定向到高级网站的登录页面上,高级网站来问用户到底要不要访问你这个低级的网站。如果用户说“要”,于是高级网站回调低级网站来告诉你用户登录了,你可以用你自己授权号来换取用户的授权号……
[/Quote]
所以新浪有个PIN码对话框确认,而QQ有个授权按键,以防止小网站恶意获得用户的微博用户名和密码,这也是OAuth的认证方式的设计。
请继续关注,希望我能得到一个好的结果。谢谢。
探花__ 2010-12-19
  • 打赏
  • 举报
回复
有点麻烦
加载更多回复(11)

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧