0

我需要能够flickr使用帐户用户名和密码将用户登录到我们的帐户。

我已经在网上搜索了很长一段时间,但只找到了一个实现的点点滴滴。我根本没有使用 Http 调用的经验。我需要一个完整的例子。这是我到目前为止的代码:

HttpWebRequest http = WebRequest.Create(url) as HttpWebRequest;
http.Method = "POST";
http.ContentType = "application/x-www-form-urlencoded";
string postData = "FormNameForUserId=" + username + "&FormNameForPassword=" +  password;
byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
http.ContentLength = dataBytes.Length;

using (Stream postStream = http.GetRequestStream())
{
    postStream.Write(dataBytes, 0, dataBytes.Length);
}

HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;

我想此时我的主要问题是弄清楚 flickr 需要哪些参数才能登录“你”。

欢迎任何建议

4

4 回答 4

1

Flickr API 需要:

API Key 
Perms (Permissions: read, write, delete) 
Frob 
API Signature

您的 URL 最终将如下所示:

http://flickr.com/services/auth/?api_key=[api_key]&perms=[perms]&frob=[frob]&api_sig=[api_sig]

构建您的 frob 和令牌的最简单方法是使用 Flickr.Net。这是一些执行此操作的代码:

Flickr ourFlickr = new Flickr();

ourFlickr.ApiSecret = ApiSecret;
ourFlickr.ApiKey = ApiKey;

string signature = ApiSecret + "api_key" + ApiKey + "methodflickr.auth.getFrob";

string frob = ourFlickr.AuthGetFrob().ToString();

string url = "http://flickr.com/services/auth/?api_key=" + ourFlickr.ApiKey + "&perms=" + "read" + " &frob=" + frob + "&api_sig=" + signature;

我希望这有帮助。无论如何,使用他们的 API 和界面将比尝试对他们的 Web 表单进行逆向工程容易得多。

于 2009-11-26T03:37:42.490 回答
1

您可以尝试使用像Fiddler这样的代理来检查您的浏览器在登录请求中发送的内容。

不过,最好的方法可能是改用Flickr APIFlickNet是 API 的 .Net 包装器。

于 2009-11-25T23:36:04.583 回答
1

确保你设置http.AllowAutoRedirect = false;了这对我来说是 2 小时头疼的原因。有时,一旦您登录,发布请求就会返回到主页的重定向。.NET 自动跟随重定向,但不会提交新获取的 cookie。>.<

于 2009-11-25T23:39:26.010 回答
1

看看这个:Flickr.net

于 2009-11-25T23:33:35.693 回答