Linq To Twitter错误 - “远程服务器返回错误:(400)错误请求”

时间:2022-06-02 20:51:41

I'm just trying to simply get the 3 latest tweets for a Twitter account:

我只想简单地获取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);
}

But I'm getting this error when I reach the line with the foreach loop:

但是当我使用foreach循环到达该行时,我收到此错误:

The remote server returned an error: (400) Bad Request.

远程服务器返回错误:(400)错误请求。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.

异常详细信息:System.Net.WebException:远程服务器返回错误:(400)错误请求。

Anyone know what I'm doing wrong?

谁知道我做错了什么?

1 个解决方案

#1


1  

LINQ to Twitter supports Twitter API v1.1, which requires OAuth authentication on every request. I understand that the error message, 400 Bad Request, is a little confusing because a 401 Unauthorized lets you know that you have an authorization problem. Maybe the 400 is because if you don't try to authenticate at all, the request isn't built properly. Anyway, I'm sure that your problem is that you need to go through the authorization process with OAuth. I wrote some OAuth documentation on the LINQ to Twitter Securing your Application page.

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

The downloadable source code has examples and there's a sample page on the site.

可下载的源代码包含示例,网站上有一个示例页面。

Once you start using OAuth, you might run into some 401 Unauthorized errors and will want to review the LINQ to Twitter FAQ.

一旦开始使用OAuth,您可能会遇到一些401 Unauthorized错误,并希望查看LINQ to Twitter常见问题解答。

Joe

#1


1  

LINQ to Twitter supports Twitter API v1.1, which requires OAuth authentication on every request. I understand that the error message, 400 Bad Request, is a little confusing because a 401 Unauthorized lets you know that you have an authorization problem. Maybe the 400 is because if you don't try to authenticate at all, the request isn't built properly. Anyway, I'm sure that your problem is that you need to go through the authorization process with OAuth. I wrote some OAuth documentation on the LINQ to Twitter Securing your Application page.

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

The downloadable source code has examples and there's a sample page on the site.

可下载的源代码包含示例,网站上有一个示例页面。

Once you start using OAuth, you might run into some 401 Unauthorized errors and will want to review the LINQ to Twitter FAQ.

一旦开始使用OAuth,您可能会遇到一些401 Unauthorized错误,并希望查看LINQ to Twitter常见问题解答。

Joe