I am trying to add a button to a desktop application that will post a picture to twitter. I have found some sample code online that uses ASP.net but it seems when I try to use it in a C# desktop application I'm getting an error with the Request and Response Names. Does anyone know why the Request and Response names would not cause any issues in ASP but would in C#. Do I need to create an httpRequest/Response?
Here is my code. Thanks for any help you can provide!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Twitterizer;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace TwitterTestApp
{
class Twitter
{
public Twitter()
{
}
public void PostPicture()
{
string oauth_consumer_key = "123456789";
string oauth_consumer_secret = "abdefg123456";
if (Request["oauth_token"] == null)
{
OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(oauth_consumer_key, oauth_consumer_secret, Request.Url.AbsoluteUri);
Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", reqToken.Token));
}
else
{
string requestToken = Request["oauth_token"].ToString();
string pin = Request["oauth_verifier"].ToString();
var tokens = OAuthUtility.GetAccessToken(oauth_consumer_key, oauth_consumer_secret, requestToken, pin);
OAuthTokens accesstoken = new OAuthTokens()
{
AccessToken = tokens.Token,
AccessTokenSecret = tokens.TokenSecret,
ConsumerKey = oauth_consumer_key,
ConsumerSecret = oauth_consumer_secret
};
byte[] photo = File.ReadAllBytes(@"C:\img.jpg");
TwitterResponse<TwitterStatus> response = TwitterStatus.UpdateWithMedia(accesstoken, "img", photo);
if (response.Result == RequestResult.Success)
{
Response.Write("This is YOUR PAGE");
}
else
{
Response.Write("Try some other time");
}
}
}
}
}