Error while Implementing Sign in with Twitter


#1

As per this Link = https://dev.twitter.com/docs/auth/implementing-sign-twitter ,

My code =
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2 {
public partial class Twitter_Variable_Calculation : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
string OAuthToken = “”;
string OAuthTokenSecret = “”;
string OAuthConsumerKey = “FvB7GZUnHdjnfslkfaGQZKPIXW07Pr”;
string OAuthConsumerSecret = “vvL1bHYt8pZDhuYjqfsdmklDSYkGd2XXB2f312flw5juwUcRHVCS”;
string oauthcallback = “http://dev-003.stits.co:33333/Twitter_Return.aspx”;
string OAuthVersion = “1.0”;
string OAuthSignatureMethod = “HMAC-SHA1”;
string OAuthNonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
string OAuthTimestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();
string ResourceUrl = “https://api.twitter.com/oauth/request_token”;

var baseFormat = “oauth_callback={0}&oauth_consumer_key={1}&oauth_nonce={2}&oauth_signature_method={3}&oauth_timestamp {4}&oauth_version={5}”;
var baseString = string.Format(baseFormat, oauthcallback,OAuthConsumerKey, OAuthNonce, OAuthSignatureMethod, OAuthTimestamp, OAuthVersion);
baseString = string.Concat(“POST&”, Uri.EscapeDataString(ResourceUrl),"&", Uri.EscapeDataString(baseString));

        var compositeKey = string.Concat(Uri.EscapeDataString(OAuthConsumerSecret), "&");
        string OAuthSignature;
        using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey))) {
        OAuthSignature = Convert.ToBase64String(hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
        }

var HeaderFormat = “OAuth " + “oauth_callback=”{0}”, " + “oauth_consumer_key=”{1}", " + “oauth_nonce=”{2}", " + “oauth_signature=”{3}", " + “oauth_signature_method=”{4}", " + “oauth_timestamp=”{5}", " + “oauth_version=”{6}"";
var authHeader = string.Format(HeaderFormat, Uri.EscapeDataString(oauthcallback), Uri.EscapeDataString(OAuthConsumerKey), Uri.EscapeDataString(OAuthNonce), Uri.EscapeDataString(OAuthSignature), Uri.EscapeDataString(OAuthSignatureMethod), Uri.EscapeDataString(OAuthTimestamp), Uri.EscapeDataString(OAuthVersion));

        ServicePointManager.Expect100Continue = false;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ResourceUrl);
        request.Headers.Add("Authorization", authHeader);
        request.Method = "POST";

        WebResponse response = request.GetResponse();
        string responseData = new StreamReader(response.GetResponseStream()).ReadToEnd();

}}}

Error = The remote server returned an error: (401) Unauthorized. OR Failed to validate oauth signature and token

Any kind of Great Knowledge is Appreciated…!
Please Help Me to Close this Issue as early as Possible Its My very bad situation pls pls pls…


#2

no one is there who will reply to my post…?