I published a LinkedIn article and I'm trying to retrieve the comments for this particular article. I obtained the articleId by right clicking on the comments button and copying the link address. I get aritcleId = 7434836657526032700. Should I use GET http://api.linkedin.com/v1/posts/{post-id}/comments where {post-id} is same as articleId?
Below is my code after successful AuthorizationLinkGet call.
string oauth_token = Request.QueryString["oauth_token"];
string oauth_verifier = Request.QueryString["oauth_verifier"];
if (oauth_token != null && oauth_verifier != null)
{
Application["oauth_token"] = oauth_token;
Application["oauth_verifier"] = oauth_verifier;
//get access token
_oauth.Token = oauth_token;
_oauth.TokenSecret = Application["reuqestTokenSecret"].ToString();
_oauth.Verifier = oauth_verifier;
_oauth.AccessTokenGet(oauth_token);
sLinkedInCommentsURL = "http://api.linkedin.com/v1/posts/7434836657526032700/comments";
string response = _oauth.APIWebRequest("GET", sLinkedInCommentsURL, null);
lblMessage.Text = response;
}
I receive following error:
Server Error in '/dreamplaybook' 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 433: finally
Line 434: {
Line 435: webRequest.GetResponse().GetResponseStream().Close();
Line 436: responseReader.Close();
Line 437: responseReader = null;
Source File: c:\inetpub\calendias\dreamplaybook\App_Code\oAuthLinkedIn.cs Line: 435
Stack Trace:
[WebException: The remote server returned an error: (403) Forbidden.]
System.Net.HttpWebRequest.GetResponse() +6538872
oAuthLinkedIn.WebResponseGet(HttpWebRequest webRequest) in c:\inetpub\calendias\dreamplaybook\App_Code\oAuthLinkedIn.cs:435
oAuthLinkedIn.APIWebRequest(String method, String url, String postData) in c:\inetpub\calendias\dreamplaybook\App_Code\oAuthLinkedIn.cs:357
adposter.Page_Load(Object sender, EventArgs e) in c:\inetpub\calendias\dreamplaybook\adposter.aspx.cs:282
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
Article ID is not the same field as post id, so that is why you are getting the error you see. The API does not allow you to get comments from publications.
Related
I am trying to get the website id from IIS on Windows Server 2012 R2. I want to fetch the Id, then add a website pointer for the website in IIS. I'm not sure where to grant the permissions for the code to work and at the same time, not leaving my web server vulnerable.
Here is my code for fetching Id
string result = "-1";
DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", "localhost"));
foreach (DirectoryEntry site in w3svc.Children)
{
if (site.Properties["ServerComment"] != null)
{
if (site.Properties["ServerComment"].Value != null)
{
if (string.Compare(site.Properties["ServerComment"].Value.ToString(),
"website.com", true) == 0)
{
result = site.Name;
break;
}
}
}
}
return result;
This is the error that is thrown:
Access is denied.
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.Runtime.InteropServices.COMException: Access
is denied.
Source Error:
Line 22: DirectoryEntry w3svc = new
DirectoryEntry(string.Format("IIS://{0}/w3svc", serverName));
Line 23:
Line 24: foreach (DirectoryEntry site in w3svc.Children)
Line 25: {
Line 26: if (site.Properties["ServerComment"] != null)
Source File: c:\inetpub\wwwroot\DNS_IIS\DNS.aspx.cs Line: 24
Stack Trace:
[COMException (0x80070005): Access is denied.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
+597561
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_IsContainer() +42
System.DirectoryServices.DirectoryEntries.GetEnumerator() +49
DNS.GetWebSiteId(String serverName, String websiteName) in c:\inetpub
\wwwroot\DNS_IIS\DNS.aspx.cs:24
DNS.btnDNS_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot
\DNS_IIS\DNS.aspx.cs:85
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3804
It was a simple thing to sort out.
So I just changed the Identity of the ApplicationPool to LocalSystem and it worked 100%.
I cannot seem to find out why my SQL data connections are not being recognized and the SQL Data Reader is not being able to read data when I publish my ASP.Net Site. It works when I just use the localhost and it is not published but once I publish it to IIS 7 it can no longer read data from SQL server. Please anyone if you can help that would great. I am very new to IIS 7 and cannot figure this out for the life of me. I have tried to check other blogs but I am coming up with nothing. The error that I am getting is:
Invalid attempt to read when no data is present.
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.InvalidOperationException: Invalid attempt to read when no data is present.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Invalid attempt to read when no data is present.]
System.Data.SqlClient.SqlDataReader.CheckDataIsReady(Int32 columnIndex, Boolean allowPartiallyReadColumn, Boolean permitAsync, String methodName) +5327847
System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn) +47
System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) +31
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) +73
System.Data.SqlClient.SqlDataReader.get_Item(String name) +27
GLIncidentRequestForm._Default.Page_Load(Object sender, EventArgs e) +318
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
web.config connection string:
Page Code:
string connString = ConfigurationManager.ConnectionStrings["NPXL_REPORTINGConnectionString"].ConnectionString;
string strAccount = HttpContext.Current.User.Identity.Name.ToString();
string strUserName = strAccount.Split('\\').Last();
txtStrName.Text = strUserName;
string selectSQL = "SELECT sAMAccountName, mail FROM ActiveDirectories WHERE mail Is Not Null and sAMAccountName = '" + txtStrName.Text + "'";
SqlConnection con = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataReader reader = default(SqlDataReader);
try
{
con.Open();
reader = cmd.ExecuteReader();
reader.Read();
txtADName.Text = reader["sAMAccountName"].ToString();
txtEmail.Text = reader["mail"].ToString();
}
finally
{
reader.Close();
con.Close();
}
I would like to add an reference for WCF weather forecast webservice in my application.The thing is I have done everything correctly,but i am lacking somewhere else.It throws an Exception.The Exception message is in the bottom of this post.Somebody out there please help me to fix this.Unles or until fixing this i couln't move to the next phase.
My Source Code is here:
public partial class Testing : System.Web.UI.Page
{
weather.WeatherForecastServiceClient ws = new weather.WeatherForecastServiceClient();
protected void Page_Load(object sender, EventArgs e)
{
SortedDictionary<string, string> objDic = new SortedDictionary<string, string>();
foreach (CultureInfo ObjectCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo objRegionInfo = new RegionInfo(ObjectCultureInfo.Name);
if (!objDic.ContainsKey(objRegionInfo.EnglishName))
{
objDic.Add(objRegionInfo.EnglishName, ObjectCultureInfo.Name);
}
}
foreach (KeyValuePair<string, string> val in objDic)
{
Country.Items.Add(new ListItem(val.Key, val.Value));
}
}
protected void callwebservice_Click(object sender, EventArgs e)
{
Result.Text = "Result" + ws.GetForecastByCity(City.SelectedItem.ToString(), Country.SelectedItem.ToString());
}
protected void Country_SelectedIndexChanged(object sender, EventArgs e)
{
string[] cities = ws.GetCitiesByCountry(Country.SelectedItem.ToString());
City.DataSource = cities;
City.DataBind();
}
}
This is my Exception
Server Error in '/' Application.
**The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
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.ServiceModel.FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
Source Error:
Line 310:
Line 311: public testing.weather.Weather GetForecastByCity(string City, string Country) {
Line 312: return base.Channel.GetForecastByCity(City, Country);
Line 313: }
Line 314: }
Source File: E:\***\WeatherForecast\testing\Service References\weather\Reference.cs Line: 312
Stack Trace:
[FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9442991
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
testing.weather.IWeatherForecastService.GetForecastByCity(String City, String Country) +0
testing.weather.WeatherForecastServiceClient.GetForecastByCity(String City, String Country) in E:\sasi\WeatherForecast\testing\Service References\weather\Reference.cs:312
testing.Testing.callwebservice_Click(Object sender, EventArgs e) in E:\sasi\WeatherForecast\testing\Testing.aspx.cs:40
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272**
You have implemented the service correctly. You can confirm this by running GetCitiesByCountry (it will return a list of cities). It is just that the method GetForecastByCity does not currently work.
Try any of these APIs instead.
I am using asp.net memebership
I log out the applcation by writting this code for log out
if (Membership.GetUser(HttpContext.Current.User.Identity).IsOnline) ;
{
FormsAuthentication.SignOut();
Response.Redirect(FormsAuthentication.LoginUrl);
}
Response.Redirect("loginpage.aspx");
After then I started the application and gettig the error in code block of authetication .below I am writtng a code and error message
else if (User.Identity.IsAuthenticated == true && Membership.GetUser( Membership.FindUsersByName(User.Identity.Name)).IsOnline==true)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
MembershipUser currUser = null;
string gt = null;
if (HttpContext.Current.User != null)
{
currUser = Membership.GetUser(true);
gt = currUser.Email;
}
/// string temp = User.Identity.GetProfile().ID;
//string query = "Insert into user_tbl(MemberID)(" + temp + ")";
//Response.Redirect("UserPanel.aspx");
//return;
}
here Membership.FindUsersByName(User.Identity.Name)).IsOnline==true) I am getting this error
[ArgumentException: The provider user key supplied is invalid. It
must be of type System.Guid. Parameter name: providerUserKey]
I am unable to find what to do , I debug the application and found User.Identity.Name as a hash value
Stack Trace
Exception Details: System.ArgumentException: The provider user key supplied is invalid. It must be of type System.Guid.
Parameter name: providerUserKey
Source Error:
Line 86: }
Line 87:
Line 88: else if (User.Identity.IsAuthenticated == true && Membership.GetUser( Membership.FindUsersByName(User.Identity.Name)).IsOnline==true)
Line 89: {
Line 90:
Source File: d:\31 May 2012\Demo\LoginPage.aspx.cs Line: 88
Stack Trace:
[ArgumentException: The provider user key supplied is invalid. It must be of type System.Guid.
Parameter name: providerUserKey]
System.Web.Security.SqlMembershipProvider.GetUser(Object providerUserKey, Boolean userIsOnline) +2242996
System.Web.Security.Membership.GetUser(Object providerUserKey, Boolean userIsOnline) +40
System.Web.Security.Membership.GetUser(Object providerUserKey) +6
LoginPage.Page_Load(Object sender, EventArgs e) in d:\31 May 2012\Demo\LoginPage.aspx.cs:88
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +36
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
Or you could also use Request.IsAuthenticated which dosent get the whole user object and just checks authentication.
According to Visual Studio, Membership.FindUsersByName returns MembershipUserCollection. You pass that object to the Membership.GetUser method, which does accept a parameter of the object type, but that object is supposed to be a user's ID (a GUID in ASP.NET). So, the exception is quite expected: you're trying to pass a collection of users, while the method expects a single user ID.
If you need to check whether a user is currently logged in, you can simply do this:
if (Membership.GetUser() != null)
See this MSDN Library article for more information on the method.
I finally got the right Facebook access token generated from the code. However now I have another problem. Using that access token to fetch user data. Every time I use the token to fetch data, it returns with an exception !String.IsNullOrEmpty(accessToken).
Full stack Trace:
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.Diagnostics.Contracts.__ContractsRuntime+ContractException: Precondition failed: !string.IsNullOrEmpty(accessToken)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ContractException: Precondition failed: !string.IsNullOrEmpty(accessToken)]
Facebook.Web.FacebookWebClient..ctor(String accessToken) +137
Facebook_Photo_App._Default.Button1_Click(Object sender, EventArgs e) in Default.aspx.cs:105
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
My code:
To generate the access token on the page load:
string code;
code = Request.QueryString["code"];
//TextBox1.Text = code;
string token;
string url = "https://graph.facebook.com/oauth/access_token?client_id=XXX&redirect_uri=http://apps.facebook.com/dutch-vegas/&client_secret=XXX&code=" + code;
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
token = reader.ReadToEnd();
string decodedtoken = token;
TextBox1.Text = decodedtoken;
decodedtoken = decodedtoken.Replace("access_token=", "");
int start = decodedtoken.IndexOf("&");
int count = decodedtoken.Length - decodedtoken.IndexOf("&");
decodedtoken = decodedtoken.Remove(start, count);
On the button implement the Access token to fetch user data
var client = new FacebookClient(decodedtoken);
dynamic me = client.Get("me");
string email = me.email;
string firstname = me.first_name;
string lastname = me.last_name;
string birthday = me.birthday;
TextBox1.Text = email;
Everything seems to be generating correctly. Even after getting the wrong access token (which was a lot shorter than it is suppose to be) for about a week, I got it sorted. And now I am stuck.
I have also noticed in the C# sdk for Facebook you can create multiple instances for FacebookWebClient, FacebookApp, FacebookClient.
Which one do I use and could this be part of my problem?
There are utility classes in the Facebook SDK that deal with the access token for you. They were a little flaky when I looked at them a few weeks ago though.
I ended up using the javascript code instead - http://www.patternwebsolutions.com/2011/03/07/facebooksdk-connect-mvc3/