Friday, October 29, 2010

The remote server returned an error: (403) Forbidden. Twitter api error

 Server Error in '/twitweb' Application.

The remote server returned an error: (403) Forbidden.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error: (403) Forbidden.

Source Error:

Line 271:            finally Line 272:            { Line 273:                webRequest.GetResponse().GetResponseStream().Close(); Line 274:                responseReader.Close(); Line 275:                responseReader = null;

Source File: c:\Inetpub\wwwroot\twitweb\App_Code\oAuthTwitter.cs    Line: 273

Stack Trace:

[WebException: The remote server returned an error: (403) Forbidden.]    System.Net.HttpWebRequest.GetResponse() +1126    oAuthExample.oAuthTwitter.WebResponseGet(HttpWebRequest webRequest) in c:\Inetpub\wwwroot\twitweb\App_Code\oAuthTwitter.cs:273    oAuthExample.oAuthTwitter.WebRequest(Method method, String url, String postData) in c:\Inetpub\wwwroot\twitweb\App_Code\oAuthTwitter.cs:244    oAuthExample.oAuthTwitter.oAuthWebRequest(Method method, String url, String postData) in c:\Inetpub\wwwroot\twitweb\App_Code\oAuthTwitter.cs:199    Default6.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\twitweb\Default6.aspx.cs:42    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42    System.Web.UI.Control.OnLoad(EventArgs e) +132    System.Web.UI.Control.LoadRecursive() +66    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428 
 
 
 
if you are using .net sample code getting this error while trying to do status update use following code in default.aspx:
 
 

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

oAuthExample;

public

partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string url = "";

string xml = "";

oAuthTwitter oAuth = new oAuthTwitter();

if (Request["oauth_token"] == null)

{

//Redirect the user to Twitter for authorization.

//Using oauth_callback for local testing.

oAuth.CallBackUrl =

"http://localhost/twitweb/default6.aspx";

Response.Redirect(oAuth.AuthorizationLinkGet());

}

else

{

//Get the access token and secret.

oAuth.AccessTokenGet(Request[

"oauth_token"], 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 = Server.HtmlEncode(xml);

//POST Test

url =

"http://twitter.com/statuses/update.xml";

xml = oAuth.oAuthWebRequest(

oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode("test 123 Hello Testing the .NET oAuth API 3"));

apiResponse.InnerHtml = Server.HtmlEncode(xml);

}

}

}

}


 

No comments: