Post Status in LinkedIn - c#

I saw one artcle how to share our status in LinkedIn using c#.
I follow those steps and the code I am using is following...
For this I am using Hammock library.
OAuthCredentials credentials = new OAuthCredentials();
credentials.Type = OAuthType.AccessToken;
credentials.ConsumerKey = "****";
credentials.ConsumerSecret = "*****";
credentials.Token = "******";
credentials.TokenSecret = "*********";
credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1;
credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader;
RestClient client = new RestClient();
client.Authority = "http://api.linkedin.com/v1";
client.Credentials = credentials;
client.Method = WebMethod.Put;
byte[] msg = Encoding.Default.GetBytes("Test");
client.AddHeader("Content-Type", "text/xml");
client.AddPostContent(msg);
RestRequest request = new RestRequest();
request.Path = "http://api.linkedin.com/v1/people/~/current-status";
/* ERROR */ RestResponse response = client.Request(request);
It's giving me a error "Bad Request."
How to solve this please help me..?

Related

Basic authentication requires a secure connection to the server. in TFS

I was try to connect my TFS server using my credentials . But i am getting error 'Basic authentication requires a secure connection to the server.'
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(basicAuthCredential)
{
AllowInteractive = false
};
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), tfsClientCredentials);
tfs.EnsureAuthenticated();
My tfs didn't have the https. Any alternative to fix it But browser level it is working fine
The BasicAuthCredential requires https://, I believe, and I wasn't able to access my TFS with https://. So I found another way to get from NetworkCredential to VssCredentials.
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
//BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(networkCredential);
VssCredentials vssCred = new VssClientCredentials(winCred);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), vssCred);
tfs.EnsureAuthenticated();
Try using the following code:
String collectionUri = "http://localhost:8080/tfs/defaultcollection";
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);

getting error like "Connection did not succeed. Try again later". using Microsoft.Exchange with delegates and Impersonation

below Useexchangeservice method used for connect mail server and getting mail from server but its showing error like "Connection did not succeed. Try again later".
static void UseExchangeService()
{
string userEmailAddress = "xyz2#domain.com";
string userPassword = "testnew#123";
ExchangeService service = new
ExchangeService(ExchangeVersion.Exchange2010_SP2);
#region Authentication
service.UseDefaultCredentials = true;
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
var folder = new FolderId(WellKnownFolderName.Calendar, new Mailbox(userEmailAddress));
#endregion
#region Endpoint management
service.AutodiscoverUrl(userEmailAddress,
RedirectionUrlValidationCallback);
#endregion
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("Lalit.Sharma2#securemeters.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("Sent by using the EWS Managed API");
email.Save(new FolderId(WellKnownFolderName.Drafts, "Lalit.Sharma2#securemeters.com"));
email.Send();
}

Email attachement using uri via smptclient and C#

i have to do the following: my documents are stored on a server. The only path i'm getting is an URI
I was trying to get the document but i'm keep getting a "403 Forbidden".
string[] myArray = context.Request.QueryString["ItemsArray"].Split(',');
MailMessage m = new MailMessage(new MailAddress("bart#schelkens.be"),
new MailAddress("bart#schelkens.be")
);
m.Subject = "Emailing documents";
foreach (string path in myArray)
{
using (WebClient wb = new WebClient())
{
wb.UseDefaultCredentials = false;
wb.Credentials = new NetworkCredential(_userName, _passWord);
var stream = wb.OpenRead(path);
m.Attachments.Add(new Attachment(stream, ""));
}
}
string mailBody = "Dear<BR/> Please find attached a new version of the documents.";
mailBody += "<BR/>";
m.Body = mailBody;
m.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("hybrid.kaneka.be");
smtp.EnableSsl = false;
smtp.Send(m);
Or is there another way to get my document from the website and then mail it?
In SharePoint I created my own button which, using a js-file, goes to my ashx to mail my documents.
Try to add the following line before opening the stream:
wb.Headers.Add("User-Agent: Other");
It could be, that it's forbidden because your server doesn't think, that you are a trusted client and blocks all connections without a User-Agent.
[edit 1]
If you try to download a file from SharePoint you have to use the SharePointOnlineCredentials from the SharePoint Server 2013 Client Components SDK:
Somewhere you have to define the credentials:
const string username = "username";
const string password = "password";
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
var credentials = new SharePointOnlineCredentials(username, securedPassword);
After that you can user this credentials in your WebClient:
wb.Credentials = credentials;
[edit 2]
If your on in an on-premises environment than you could use NetworkCredentials. Try to use the following:
wb.Credentials = new NetworkCredential("DOMAINNAME\username", "password");
[edit 3]
Maybe your server wants a real User-Agent. Because if something is wrong with your credentials there would be a 401 (unauthorized). For example try:
wb.Headers.Add("user-agent", " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
Provide the READ/WRITE rights/permission on the folder where your document is located.
Currently there is no read/write rights/permission on that folder that's why when ever you try to attach the document it returns 403 Forbidden error.

Getting error while Authenticating online TFS from WCF service

I am trying to connect online TFS using WCF service but it is throwing me exception "TF30063: You are not authorized to access https://abdul-r.visualstudio.com/DefaultCollection/TestTFS.".
Below is my sample code
NetworkCredential netCred = new NetworkCredential(
"*MyEmail*",
"*MyPassword*");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials credential = new TfsClientCredentials(basicCred);
credential.AllowInteractive = false;
string TFSServerPath = "https://abdul-r.visualstudio.com/DefaultCollection/TestTFS";
using (TfsTeamProjectCollection tfs1 = new TfsTeamProjectCollection(new Uri(TFSServerPath), credential))
{
tfs1.EnsureAuthenticated();
}
Any help would be appreciated.

HttpClient with Authentication returns 404. Why?

I have an API that needs authentication with username and password. I can't figure out why my code fails and the response is 404, when I'm doing a GET method and give the actual credentials:
NetworkCredential networkCredentials = new System.Net.NetworkCredential("adminUN", "mypassword");
HttpClientHandler handler = new HttpClientHandler();
handler.PreAuthenticate = true;
handler.Credentials = networkCredentials;
httpClient = new HttpClient(handler);
HttpResponseMessage response = await httpClient.GetAsync(GlobalDeclarations.strURL);

Categories

Resources