Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
Last active August 29, 2015 13:57
Show Gist options
  • Save firstspring1845/9409709 to your computer and use it in GitHub Desktop.
Save firstspring1845/9409709 to your computer and use it in GitHub Desktop.
OAuthBase.cs使ってTwitterに投稿してみる
using OAuth;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Web;
namespace Test
{
class Twitter
{
const String CK = "";
const String CS = "";
const String T = "";
const String TS = "";
public static void Main(string[] args)
{
var o = new OAuthBase();
var u = "https://api.twitter.com/1.1/statuses/update.json?status=test";
String nu;
String nrp;
var sign = o.GenerateSignature(new Uri(u), CK, CS, T, TS, "POST", o.GenerateTimeStamp(), o.GenerateNonce(), out nu, out nrp);
var h = "OAuth " + String.Join(", ",(nrp + "&oauth_signature=" + HttpUtility.UrlEncode(sign)).Split('&').Select(s => Regex.Replace(s, "(.+)=(.+)", "$1=\"$2\"")));
var r = WebRequest.Create(u);
r.Headers.Add("Authorization", h);
r.Method = "POST";
r.GetResponse();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment