Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 验证Twitter用户并在其帐户C上发布推文#_C#_Asp.net_Api_Twitter - Fatal编程技术网

C# 验证Twitter用户并在其帐户C上发布推文#

C# 验证Twitter用户并在其帐户C上发布推文#,c#,asp.net,api,twitter,C#,Asp.net,Api,Twitter,我有一个asp.net c#页面,其中有三个文本框和一个发布推文的按钮 1) 输入用户名 2) 输入密码 3) 推文 4) 发布推文按钮 问题是我想在用户帐户上发布tweet。 在我的网页上,第一个用户将输入他的用户名和密码。我将验证twitter上的用户信息,然后在他自己的帐户上发布推文 我们可以在Twitterizer中执行类似的操作 Twitter=newtwitter(“用户名”、“密码”、“来源”) twitter.Status.Update(“更新”) 我知道现在我们不能使用推特 我

我有一个asp.net c#页面,其中有三个文本框和一个发布推文的按钮

1) 输入用户名

2) 输入密码

3) 推文

4) 发布推文按钮

问题是我想在用户帐户上发布tweet。 在我的网页上,第一个用户将输入他的用户名和密码。我将验证twitter上的用户信息,然后在他自己的帐户上发布推文

我们可以在Twitterizer中执行类似的操作

Twitter=newtwitter(“用户名”、“密码”、“来源”)

twitter.Status.Update(“更新”)

我知道现在我们不能使用推特

我使用了下面链接中提到的示例,但它也不起作用

示例代码 ///////////////////////////////////////////////////////////////////////////////////////////////////

public bool CheckTwitterCredentials(string UserName, string Password)
{
    // Assume failure
    bool Result = false;

    // A try except block to handle any exceptions
    try {
        // Encode the user name with password
        string UserPass = Convert.ToBase64String(
            System.Text.Encoding.UTF8.GetBytes(UserName + ":" + Password));

        // Create our HTTP web request object
        HttpWebRequest Request = 
            (HttpWebRequest)WebRequest.Create("http://twitter.com/account/verify_credentials.xml");

        // Set up our request flags and submit type
        Request.Method = "GET";
        Request.ContentType = "application/x-www-form-urlencoded";

        // Add the authorization header with the encoded user name and password
        Request.Headers.Add("Authorization", "Basic " + UserPass);

        // Use an HttpWebResponse object to handle the response from Twitter
        HttpWebResponse WebResponse = (HttpWebResponse)Request.GetResponse();

        // Success if we get an OK response
        Result = WebResponse.StatusCode == HttpStatusCode.OK;
    } catch (Exception Ex) {
        System.Diagnostics.Debug.WriteLine("Error: " + Ex.Message);
    }

    // Return success/failure
    return Result;
}
///////////////////////////////////////////////////////////////////////////////////////////////

public bool CheckTwitterCredentials(string UserName, string Password)
{
    // Assume failure
    bool Result = false;

    // A try except block to handle any exceptions
    try {
        // Encode the user name with password
        string UserPass = Convert.ToBase64String(
            System.Text.Encoding.UTF8.GetBytes(UserName + ":" + Password));

        // Create our HTTP web request object
        HttpWebRequest Request = 
            (HttpWebRequest)WebRequest.Create("http://twitter.com/account/verify_credentials.xml");

        // Set up our request flags and submit type
        Request.Method = "GET";
        Request.ContentType = "application/x-www-form-urlencoded";

        // Add the authorization header with the encoded user name and password
        Request.Headers.Add("Authorization", "Basic " + UserPass);

        // Use an HttpWebResponse object to handle the response from Twitter
        HttpWebResponse WebResponse = (HttpWebResponse)Request.GetResponse();

        // Success if we get an OK response
        Result = WebResponse.StatusCode == HttpStatusCode.OK;
    } catch (Exception Ex) {
        System.Diagnostics.Debug.WriteLine("Error: " + Ex.Message);
    }

    // Return success/failure
    return Result;
}
现在twitter已经提供了一些与dotnetc#配合使用的库

.NET

•LINQ2Twitter作者@joemayo(示例)

•SpringSource为Twitter提供的Spring.NET社交扩展-一个Spring.NET社交扩展,具有连接支持和Twitter的API绑定

•TweetSharp by@danielcrenna-用于访问Twitter API的.net库

•由Linvi维护的Tweetinvi——一个Twitter.NETC#API,其使命是简化C#中Twitter应用程序的开发。该流媒体API已用于研究项目,每天收集约320万条推特。TwitterAPI的创建是为了便于实现新功能,目前提供了对大多数功能的访问。(文件)

•由@martbrow制作的.Twitter—一种缓存兼容解决方案—具有ASP.Net Web表单和MVC的实现。使您的网站更容易包含推文

我使用了以下库API。在下面的链接中提到

//设置您的凭据()

但问题是,它是在我自己创建的twitter页面上发布的,而不是在其他用户的twitter页面上发布的

我想要的是,通过使用上述更新的库,用户是否可以在我的页面上输入用户名和密码,以及tweet的一些细节,并在自己的帐户上发布tweet

请告诉我这是否现在可能

谢谢


Syyed

我是Tweetinvi的开发者

Twitter应用程序不再公开使用用户名/密码身份验证。相反,Twitter现在要求开发人员使用OAuth

这对你来说意味着,为了在你的应用程序上进行身份验证,他们必须从twitter.com网站接受你的应用程序

为此,TwitterRESTAPI提供了2个身份验证过程。基于PIN和URL重定向。建议网站使用URL重定向

您可以在此处了解更多信息:

我还建议您查看一下,以便更好地了解身份验证机制

最后,我建议您查看一下,或者哪个MVC项目正是您想要做的:
Authentication+Post Tweet

如果你有更多的问题之后,我会很乐意帮助更多

干杯, Linvi

试试下面的代码:

var tweet = Search.SearchTweets("stackoverflow");
var textToPublish = $"@{tweet.CreatedBy.ScreenName}";
var reply = Tweet.PublishTweet(new PublishTweetParameters(textToPublish)
                {
                    InReplyToTweet = tweet
                });

嗨,林薇,谢谢你的回复。作为一名开发者,你在tweetinvi上做得很好。我已经检查了你在回复中提到的MVC项目。问题是,我想在用户twitter页面上,而不是在我自己的twitter创建的应用程序上,共享一个带有图像的产品。在感谢中,我们指向Examplinvi.web的链接已失效。@Matthia感谢您的反馈,该链接现在已更新。