Linq到Twitter已通过身份验证,但会收到215个“错误的身份验证数据" [英] Linq to Twitter Authenticated But Getting 215 "Bad Authentication Data"
问题描述
我一直在使用Linq to Twitter进行Twitter API 1.1的OAuth身份验证. 我设置了凭据,然后将它们传递给Linq到Twitter,其中声明我isAuth返回true.但是,在运行时,我在215处收到身份验证数据错误"错误.还有其他人有这个问题吗?
I have been using Linq to Twitter for Authenticating with OAuth for the Twitter API 1.1. I set my credentials and then pass them to Linq to Twitter which states I that isAuth returns true. However, at run time I receive at 215 "Bad Authentication Data" error. Has anyone else had this problem?
var auth = new SingleUserAuthorizer
{
Credentials = new InMemoryCredentials
{
ConsumerKey = TwitterSettings.ConsumerKey,
ConsumerSecret = TwitterSettings.ConsumerKeySecret,
OAuthToken = TwitterSettings.AccessToken,
AccessToken = TwitterSettings.AccessTokenSecret,
}
};
auth.Authorize();
}
这是如果有的话,说明我已被授权:
And here is the if else that is stating I am authorized:
if (auth == null || !auth.IsAuthorized)
{
}
// If Twitter Authorizes Application
if (auth.IsAuthorized && i == 1)
{
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(new Uri("https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4"));
string json = await response.Content.ReadAsStringAsync();
JObject obj = JObject.Parse(json);
var jsonResults = obj["results"];
await JsonConvert.DeserializeObjectAsync<List<Tweet>>(jsonResults.ToString());
}
我能够进入代码的auth.IsAtuhorized部分,但是响应返回215错误.我也知道我的URI是正确的,因为我直接从Twitter API 1.1示例页面复制了它来测试调用.在此先感谢
I am able to get into the auth.IsAtuhorized portion of the code but the response is returning a 215 error. Also I know my URI is correct because I copied it straight from the Twitter API 1.1 example page to test the call. Thanks in Advance
推荐答案
您正确使用了授权程序,但是您没有使用LINQ to Twitter进行查询.您使用的是HttpClient,这两个API之间没有关系.这是一个如何使用LINQ to Twitter进行搜索的示例:
You're using the authorizer properly, but then you aren't using LINQ to Twitter to make your query. You're using HttpClient instead and there isn't a relationship between the two APIs. Here's a example of how to perform a Search with LINQ to Twitter:
var srch =
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == "LINQ to Twitter" &&
search.Count == 7
select search)
.SingleOrDefault();
Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query);
srch.Statuses.ForEach(entry =>
Console.WriteLine(
"ID: {0, -15}, Source: {1}\nContent: {2}\n",
entry.StatusID, entry.Source, entry.Text));
您可以访问 LINQ to Twitter搜索文档,以获取有关可用参数的更多信息.
You can visit the LINQ to Twitter Search Documentation for more info on available parameters.
更新,这是一个异步示例:
Update, Here's an asynchronous sample:
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == QueryTextBox.Text
select search)
.MaterializedAsyncCallback(asyncResponse =>
Dispatcher.BeginInvoke(() =>
{
if (asyncResponse.Status != TwitterErrorStatus.Success)
{
MessageBox.Show("Error during query: " + asyncResponse.Exception.Message);
return;
}
Search search = asyncResponse.State.SingleOrDefault();
var tweets =
(from status in search.Statuses
select new Tweet
{
UserName = status.User.Identifier.ScreenName,
Message = status.Text,
ImageSource = status.User.ProfileImageUrl
})
.ToList();
SearchListBox.ItemsSource = tweets;
}));
这篇关于Linq到Twitter已通过身份验证,但会收到215个“错误的身份验证数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!