Here's some of the code I'm using to send the tweet...
string postData = "Hello World";
Uri taskUri = new Uri (https://api.twitter.com/1/statuses/update.json);
client = new WebClient();
var content = new StringBuilder ();
content.AppendFormat ("status={0}", OAuth.PercentEncode (postData));
client.Headers [HttpRequestHeader.Authorization] =
OAuthAuthorizer.AuthorizeRequest (TwitterAccount.OAuthConfig, twitterToken,
twitterSecret, "POST", taskUri, content.ToString());
var res = client.UploadData (taskUri, "POST", Encoding.UTF8.GetBytes
(postData));
public static string AuthorizeRequest (OAuthConfig config, string
oauthToken, string oauthTokenSecret, string method, Uri uri, string data)
{
var headers = new Dictionary<string, string>()
{
{ "oauth_consumer_key", config.ConsumerKey },
{ "oauth_nonce", MakeNonce () },
{ "oauth_signature_method", "HMAC-SHA1" },
{ "oauth_timestamp", MakeTimestamp () },
{ "oauth_token", oauthToken },
{ "oauth_version", "1.0"},
};
var signatureHeaders = new Dictionary<string,string>
(headers);
// Add the data and URL query string to the copy of the
headers for
computing the signature
if (!string.IsNullOrEmpty(data))
{
var parsed = HttpUtility.ParseQueryString
(data);
foreach (string k in parsed.Keys)
{
signatureHeaders.Add (k,
OAuth.PercentEncode (parsed [k]));
}
}
var nvc = HttpUtility.ParseQueryString (uri.Query);
foreach (string key in nvc)
{
if (key != null)
signatureHeaders.Add (key,
OAuth.PercentEncode (nvc [key]));
}
string signature = MakeSignature (method,
uri.GetLeftPart
(UriPartial.Path), signatureHeaders);
string compositeSigningKey = MakeSigningKey
(config.ConsumerSecret,
oauthTokenSecret);
string oauth_signature = MakeOAuthSignature
(compositeSigningKey,
signature);
headers.Add ("oauth_signature", OAuth.PercentEncode
(oauth_signature));
return HeadersToOAuth (headers);
}
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/Simple-Tweet-code-example-tp4074835p4078324.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch