私はこれが以前に何度も尋ねられたことを知っていますが、私はこれを達成するためにここにある他の投稿と一緒にlinqtotwitterドキュメントと例からの情報を使用しました。新しいアプリにツイートを送信させることはできますが、Twitterの承認ページに移動させて、続行するには承認ボタンをクリックする必要があります。
アプリ自体は正常に承認されているので、毎回パスワードは必要ありません。許可が必要なのはアプリの使用だけです。
これの理由は、私のコードのどこにもアクセストークンまたはアクセストークンシークレットがないためです。それらを追加しましたが、401が無許可(無効または期限切れのトークン)になるたびに。
私のコードは次のとおりです、おそらくあなたは私がどこで間違っているのか見ることができますか?
private IOAuthCredentials credentials = new SessionStateCredentials();
private MvcAuthorizer auth;
private TwitterContext twitterCtx;
public ActionResult Index()
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
credentials.AccessToken = "MYaccessTOKENhere"; // Remove this line and line below and all works fine with manual authorisation every time its called //
credentials.OAuthToken = "MYaccessTOKENsecretHERE";
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
if (!auth.IsAuthorized)
{
Uri specialUri = new Uri(Request.Url.ToString());
return auth.BeginAuthorization(specialUri);
}
twitterCtx = new TwitterContext(auth);
twitterCtx.UpdateStatus("Test Tweet Here"); // This is the line it fails on //
return View();
}