gpt4 book ai didi

c# - 尝试使用 Linq to Twitter 发推文时出现 401

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:44 25 4
gpt4 key购买 nike

所以我查看了 Linq to Twitter 文档中关于 Oauth 401 状态的所有建议,老实说我不知道​​我做错了什么。

var auth = new PinAuthorizer
{
Credentials = new InMemoryCredentials
{
ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
//OAuthToken = ConfigurationManager.AppSettings["twitterOAuthToken"], //don't include this
//AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"] //or this for new users.
},
//
UseCompression = true,
GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
GetPin = () =>
{
Console.WriteLine("/nAfter twitter authorizes your application you will be returned here or something/n");
Console.Write("Enter Pin here:");
return Console.ReadLine();
}

};

auth.Authorize();


using (var twitterCtx = new TwitterContext(auth, "https://api.twitter.com/1/",
"https://search.twitter.com/"))
{

try
{
twitterCtx.Log = Console.Out;
Console.WriteLine("Please provide tweet text");
string tweet = Console.ReadLine();

twitterCtx.UpdateStatus(tweet);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}


}

我已经使用 Pin 身份验证方法和单用户方法(通过配置文件提供 oauth key )运行了此程序。我可以查询推文,但无法更新我的状态或发送直接消息(当我尝试发送 DM 时收到 403 禁止)。我提供了一个回调 URL(虽然是假的)所以我想不出为什么这不起作用。任何帮助将不胜感激。

PS 这在 Main 中运行,不确定这是否重要

最佳答案

您只需要重载 TwitterContext 构造函数,它将使用正确的基本 URL:

new TwitterContext(auth)

您使用的示例是针对 v1.0 URL 的,LINQ to Twitter 现在在 Twitter API v1.1 上。它将默认为正确的基本 URL。

如果您查询正常,但在更新和 DM 时出现错误,请仔细检查以确保您没有尝试发布相同的文本。这就是为什么我将 DateTime.Now 附加到测试推文的末尾 - 以保证唯一性。

关于c# - 尝试使用 Linq to Twitter 发推文时出现 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15755420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com