logoSign upLog in
Francisco Javier Hernandez Duque

Francisco Javier Hernandez Duque

Twitter API for beginners
using System.Net;
using System.IO;
tring access_token = "";
var post = WebRequest.Create("https://api.twitter.com/oauth2/token") as HttpWebRequest;
post.Method = "POST";
post.ContentType = "application/x-www-form-urlencoded";
post.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
var reqbody = Encoding.UTF8.GetBytes("grant_type=client_credentials");
post.ContentLength = reqbody.Length;
using (var req = post.GetRequestStream())
{
req.Write(reqbody, 0, reqbody.Length);
}
try
{
string respbody = null;
using (var resp = post.GetResponse().GetResponseStream())//there request sends
{
var respR = new StreamReader(resp);
respbody = respR.ReadToEnd();
}
//TODO use a library to parse json
access_token = respbody.Substring(respbody.IndexOf("access_token\":\"") + "access_token\":\"".Length, respbody.IndexOf("\"}") - (respbody.IndexOf("access_token\":\"") + "access_token\":\"".Length));
}
catch //if credentials are not valid (403 error)
{
//TODO
}
Articulo completo en
http://www.codeproject.com/Tips/1076400/Twitter-API-for-beginners

Relevant