1
在試圖在http://www.voiceoftech.com/swhitley/?p=681落實Twitter的代碼,我得到一個編譯時錯誤:讓C#談論Twitter。 (C#新用戶的問題範圍。?)
The name 「apiResponse does not exist in the current context」,
通常我會被完全限定呼叫解決這種類型的問題,例如,而不是說:
Response.Redirect(oAuth.AuthorizationLinkGet());
我反而說:
System.Web.HttpContext.Current.Response.Redirect(oAuth.AuthorizationLinkGet());
的問題是,我不知道該怎麼做機智h apiResponse問題。有任何想法嗎?
下面是相關代碼文件:
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);
}
}
}
}
}
謝謝。我試圖將其作爲桌面應用程序(Windows窗體應用程序)來實現。這是否改變了事情? – Dirk 2010-12-08 14:58:29