我正在尝试使用linq向twitter发送一个简单的状态更新(推文)。我可以连接好,但是当我发送推文时,我会使用以下代码获得“故障”的返回状态。
public async Task Tweet(string text)
{
var auth = GetCredentials();
await auth.AuthorizeAsync();
var ctx = new TwitterContext(auth);
var tweet = ctx.TweetAsync(text);
if (tweet != null)
Console.WriteLine(tweet.Status);
}
我的GetCredentials方法如下:
private static SingleUserAuthorizer GetCredentials()
{
return new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore()
{
ConsumerKey = ####,
ConsumerSecret = ####,
AccessToken = ####,
AccessTokenSecret = ####,
}
};
}
确认我在twitter上创建了一个应用程序。凭证是正确的(或至少从Twitter复制和粘贴),我有完全的权限将消息发布到相关帐户。
答案 0 :(得分:1)
您应该等待 TweetAsync ,如下所示:
Status tweet = await ctx.TweetAsync(text);
这仍然无法一直解决你的问题,原因如下:
答案 1 :(得分:0)
感谢Joe的回答,我能够深入挖掘我的。
使用他建议的代码并捕获异常我能够抓住这个错误:
Could not load file or assembly ‘System.Net.Http.Primitives, Version=1.5.0.0
我为Microsoft.Net.Http重新编写了这个程序,这个程序栩栩如生。
已安装库但未正确添加到配置文件中。