Last active
August 29, 2015 13:57
-
-
Save firstspring1845/9409709 to your computer and use it in GitHub Desktop.
OAuthBase.cs使ってTwitterに投稿してみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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