In trying to implement the Twitter code at http://www.voiceoftech.com/swhitley/?p=681 I am getting a compile time error:
The name “apiResponse does not exist in the current context”,
Usually I would fix a problem of this type by fully qualifying the call, for example instead of saying:
Response.Redirect(oAuth.AuthorizationLinkGet());
I would instead say:
System.Web.HttpContext.Current.Response.Redirect(oAuth.AuthorizationLinkGet());
The problem is, I have no idea what to do with the apiResponse problem. Any ideas?
Here is the relevant code file:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Collections.Specialized;
namespace ArduinoSerialCommTest
{
class Tweet
{
protected void Page_Load(object sender, EventArgs e)
{
string url = "";
string xml = "";
oAuthTwitter oAuth = new oAuthTwitter();
if (System.Web.HttpContext.Current.Request["oauth_token"] == null)
{
//Redirect the user to Twitter for authorization.
//Using oauth_callback for local testing.
oAuth.CallBackUrl = "http://localhost";
System.Web.HttpContext.Current.Response.Redirect(oAuth.AuthorizationLinkGet());
}
else
{
//Get the access token and secret.
oAuth.AccessTokenGet(System.Web.HttpContext.Current.Request["oauth_token"], System.Web.HttpContext.Current.Request["oauth_verifier"]);
if (oAuth.TokenSecret.Length > 0)
{
//We now have the credentials, so make a call to the Twitter API.
url = "http://twitter.com/account/verify_credentials.xml";
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
apiResponse.InnerHtml = System.Web.HttpContext.Current.Server.HtmlEncode(xml);
//POST Test
//url = "http://twitter.com/statuses/update.xml";
//xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode("Hello @swhitley - Testing the .NET oAuth API"));
//apiResponse.InnerHtml = Server.HtmlEncode(xml);
}
}
}
}
}
apiResponseis a server side div in aaspxpage. Please check again. If you do not have any div there, put the following there.