[twitter-dev] Re: Authentication failing for status POST in C#

2010-09-14 Thread hyronymous
Woops, sorry and the response that I get back is:

{"request":"/1/statuses/update.json","error":"Incorrect signature"}

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk?hl=en


[twitter-dev] Re: Authentication failing for status POST in C#

2010-09-14 Thread hyronymous
The base string is:

POST&http%3a%2f%2fapi.twitter.com%2f1%2fstatuses
%2fupdate.json&oauth_consumer_key%3dA5l9hSVM5Hznf5p1pBwNsg
%26oauth_nonce%3dJOCvtqemMQg1k0XnFjbH0MQPxr6Yme7zcei6mZO6ZP
%26oauth_signature_method%3dHMAC-SHA1%26oauth_timestamp
%3d1284512080%26oauth_token%3d189085164-
UGuVwmGtljgvSUg8q0aCOD4vrPibePTE7zVBlOMG%26oauth_version%3d1.0%26status
%3doogyboogy

The sent request is:

POST /1/statuses/update.json HTTP/1.1\r\n
Authorization: OAuth
oauth_nonce="JOCvtqemMQg1k0XnFjbH0MQPxr6Yme7zcei6mZO6ZP",oauth_signature_method="HMAC-
SHA1",oauth_timestamp="1284512080",oauth_consumer_key="A5l9hSVM5Hznf5p1pBwNsg",oauth_token="189085164-
UGuVwmGtljgvSUg8q0aCOD4vrPibePTE7zVBlOMG",oauth_signature="62%2BaTNj5jKWl7ajQrzM
%2FNQXV7Rw%3D",oauth_version="1.0"\r\n
Content-Type: application/x-www-form-urlencoded\r\n
Host: api.twitter.com\r\n
Content-Length: 16\r\n
\r\n
status=oogyboogy

On Sep 10, 12:00 pm, Tom van der Woerdt  wrote:
> I like code, but I like seeing the results even more :-)
>
> Can you provide us (the twitter-dev list) with these :
> * A base string
> * A full request and response
>
> Tom
>
> On 9/10/10 8:22 PM, hyronymous wrote:
>
>
>
> > So far as I can tell, I'm following the instructions accurately
> > according tohttp://dev.twitter.com/pages/auth, but regardless of any
> > minute variations, I keep getting a 401, authorization error on
> > posting (i.e. the method pushMessage() fails). So far as I can tell,
> > I'm not doing anything different, other than using POST, than I did
> > during the initial authorization.
>
> > public class Twitter {
> >    private string tokenSecret = "";
>
> >    private string createTimestamp() {
> >            var now = DateTime.UtcNow;
> >            var then = new DateTime(1970, 1, 1);
> >            var timespan = now - then;
> >            return ("" + (long)timespan.TotalSeconds);
> >    }
>
> >    private string createNonce() {
> >            const string ALPHANUMERIC =
> >                      "qwertyuiopasdfghjklzxcvbnm"
> >                    + "QWERTYUIOPASDFGHJKLZXCVBNM"
> >                    + "1234567890"
> >            ;
>
> >            var sb = new StringBuilder();
> >            var random = new Random();
> >            for (int L = 0; L < 42; L++)
> >            {
> >                    sb.Append(
> >                            ALPHANUMERIC[random.Next(ALPHANUMERIC.Length)]
> >                    );
> >            }
> >            return sb.ToString();
> >    }
>
> >    private string createSignature(string signatureBase) {
> >            string key = clientSecret + "&" + tokenSecret;
> >            var keyBytes = Encoding.UTF8.GetBytes(key);
> >            var sigMethod = new HMACSHA1(keyBytes);
>
> >            byte[] data = Encoding.UTF8.GetBytes(signatureBase);
> >            var hash = sigMethod.ComputeHash(data);
> >            var sig = Convert.ToBase64String(hash);
>
> >            sig = Uri.EscapeDataString(sig);
> >            return sig;
> >    }
>
> >    private void myInit() {
> >            int found = 0;
> >            string[] words = sessionData.Split('&');
> >            for (uint L = 0; L < words.Length; L++)
> >            {
> >                    if (words[L].StartsWith("oauth_token="))
> >                    {
> >                            ++found;
> >                            accessToken = words[L];
> >                    }
> >                    else if (words[L].StartsWith("oauth_token_secret="))
> >                    {
> >                            ++found;
> >                            tokenSecret = 
> > words[L].Substring("oauth_token_secret=".Length);
> >                    }
> >                    else if (words[L].StartsWith("user_id=")) {
> >                            ++found;
> >                            userID = words[L].Substring("user_id=".Length);
> >                    }
> >                    else if (words[L].StartsWith("screen_name=")) {
> >                            ++found;
> >                            screenName = 
> > words[L].Substring("screen_name=".Length);
> >                    }
> >            }
> >            if (found != 4) {
> >                    throw new Exception("Unknown response from server");
> >            }
> >    }
>
> >    public new void createSession(System.Web.UI.Page page)
> >    {
> >            if (
> >                    
> > !string.IsNullOrEmpty(page.Request.QueryString["oauth_token"])
> >            ) {
> >                    string timestamp = createTimestamp();
> >                    string nonce = createNonce();
>
> >                    var sigBase =
> >                            "GET"
> >                            + "&" + 
> > Uri.EscapeDataString("https://api.twitter.com/oauth/
> > access_token")
> >                            + "&" + 
> > Uri.EscapeDataString("oauth_consumer_key=" + clientID)
> >                            + "%26" + Uri.EscapeDataString("oauth_nonce=" + 
> > nonce)
> >                            + "%26" + 
> > Uri.EscapeDataString("o