【问题标题】:Linq To Twitter error - "The remote server returned an error: (400) Bad Request"Linq To Twitter 错误 - “远程服务器返回错误:(400) 错误请求”
【发布时间】:2012-12-13 07:19:56
【问题描述】:

我只是想简单地获取 Twitter 帐户的 3 条最新推文:

List<string> tweets = new List<string>();
var twitterCtx = new TwitterContext();

statusTweets =
    tweet in twitterCtx.Status
    where tweet.Type == StatusType.User &&
        tweet.Count == 3 &&
        tweet.ID == "shanselman"
    select tweet;

foreach (var statusTweet in statusTweets)
{
    tweets.Add(statusTweet.Text);
}

但是当我到达foreach 循环的行时出现此错误:

远程服务器返回错误:(400) Bad Request。

说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详情:System.Net.WebException:远程服务器返回错误:(400) Bad Request。

有人知道我做错了什么吗?

【问题讨论】:

  • 您是否检查过您没有遇到 Twitter 的速率限制?当您在一小时内超过 150 个请求时,您将获得 400。
  • 你能发布 fiddler 捕获的请求吗?并在那里检查响应正文,它可能包含错误描述

标签: c# asp.net linq twitter linq-to-twitter


【解决方案1】:

LINQ to Twitter 支持 Twitter API v1.1,它要求对每个请求进行 OAuth 身份验证。我知道错误消息 400 Bad Request 有点令人困惑,因为 401 Unauthorized 让您知道您遇到了授权问题。也许 400 是因为如果您根本不尝试进行身份验证,则请求没有正确构建。无论如何,我确定您的问题是您需要使用 OAuth 完成授权过程。我在 LINQ to Twitter Securing your Application 页面上写了一些 OAuth 文档。

可下载的源代码有示例,网站上有sample page

一旦您开始使用 OAuth,您可能会遇到一些 401 Unauthorized 错误并需要查看 LINQ to Twitter FAQ

【讨论】:

    猜你喜欢
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    相关资源
    最近更新 更多