在深入挖掘了 TweetSharp 的源代码之后,我在层层层层地迷失了方向……就像试图在 20 个干草堆中找一根针一样。我很欣赏 Tweetinvi Linvi 的链接,但我决定今晚锻炼一下我的大脑,看看我是否可以从头开始写。
我花了一些时间查看我在 Twitter 上可以找到的内容,他们执行 OAuth 的方式非常时髦。然后我找到了一个处理 OAuth 的 PHP 解决方案,并对其进行了一些调整以使其返回电子邮件地址。有了这些,我将 PHP 翻译成 C#,并在我自己的家庭解决方案中完成了所有工作。
我刚刚在这里发布了我的工作解决方案:http://www.burritostand.com/log-in-to-twitter-with-oauth-and-c-sharp-and-get-twitter-user-email
它需要进行一些重大的重构以使其成为具有生产价值的实现,但我认为它可能对其他人有用,因为它非常清楚地分解了不同的过程。希望其他人可以使用它。
关键部分(用于检索电子邮件)在 TwitterClient 类中,在参数列表中:
TwitterUrls TwitterUrls = new TwitterUrls("https://api.twitter.com/1.1/account/verify_credentials.json");
List<KeyValuePair<string, string>> Parameters = new List<KeyValuePair<string, string>>();
Parameters.Add(new KeyValuePair<string, string>("include_email", "true")); // this is the important part for getting the email returned
Parameters.Add(new KeyValuePair<string, string>("oauth_consumer_key", ConsumerKey));
Parameters.Add(new KeyValuePair<string, string>("oauth_nonce", Nonce));
Parameters.Add(new KeyValuePair<string, string>("oauth_signature_method", "HMAC-SHA1"));
Parameters.Add(new KeyValuePair<string, string>("oauth_timestamp", timestamp));
Parameters.Add(new KeyValuePair<string, string>("oauth_token", dict["oauth_token"]));
Parameters.Add(new KeyValuePair<string, string>("oauth_version", OAuthVersion));
感谢您的回答,今晚回到 PHP 确实很开心……时间很长 :)