c# - How to reply for comment in LinkedIn? - c#

I'm trying to integrate LinkedIn in our application. I just want to know how to reply for comment in LinkedIn.
I've written this code.
protected void Page_Load(object sender, EventArgs e)
{
string data = "<comments><comment><text>Check out the Reply!</text></comment></comments>";
byte[] databytes = Encoding.UTF8.GetBytes(data);
var request = new RestRequest { Path = "comments" };
var credentials = new Hammock.Authentication.OAuth.OAuthCredentials
{
Type = OAuthType.AccessToken,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = "kmkzt9cqml1s",
ConsumerSecret = "hNiwIrZWGSMykoD2",
Token = "b3cbdca7-37a7-474f-a9a6-e21bb89917fe",
TokenSecret = "990f1b78-79de-4490-b4e3-893b4e020e45",
};
var client = new RestClient()
{
Authority = "http://api.linkedin.com/v1/posts/g-457832-S-454334",
Credentials = credentials,
Method = WebMethod.Post,
};
client.AddHeader("Content-Type", "text/xml");
client.AddPostContent(databytes);
RestResponse response = client.Request(request);
string content = response.Content;
}
I'm getting an error in content in the below format
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<error>
<status>400</status>
<timestamp>1374494502579</timestamp>
<request-id>QM4MYPEKJJ</request-id>
<error-code>0</error-code>
<message>Couldn't parse message document: error: Unexpected end of file after null</message>\n</error>\n"
Any ideas? Thanks in advance.

Related

Getting parameter_rejected error in quickbook online integration

I have done this code:
static void Main (string[] args)
{
Console.WriteLine("Authenticating..");
string consumerkey = "L0ORES0pf0uEody1YDI3sTkTpyBGaDVVnVRBb1krprkrghPWLQ";
string consumerSecret = "NAONcYrwGgpkFCJN2BgXZHjG8YLqn1JWMEPDXIMg";
string REQUEST_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_request_token";
string ACCESS_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_access_token";
string OauthLink = "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl";
var consumerContext = new OAuthConsumerContext
{
ConsumerKey = consumerkey,
ConsumerSecret = consumerSecret,
SignatureMethod = SignatureMethod.HmacSha1
};
IOAuthSession AuthSession = new OAuthSession(consumerContext,REQUEST_TOKEN_URL, OauthLink, ACCESS_TOKEN_URL);
IToken requestToken = AuthSession.GetRequestToken();
}
And I am getting error : An unhandled exception of type 'DevDefined.OAuth.Framework.OAuthException' occurred in DevDefined.OAuth.dll Additional information: parameter_rejected
I have attached screenshot of my error.
What is quickbook online Request token URL and Access token URL for OAuth 2.0?
Oauth2.0 //Refresh and Get New Access Token through WebClient and build ServiceContext for CRUD operations
Access Token will expire in every 60 minutes
string URI = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer";
string myParameters = "grant_type=refresh_token&refresh_token=L0115-----------------------------------"; // Put Refresh Token
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers[HttpRequestHeader.Accept] = "application/json";
wc.Headers[HttpRequestHeader.Authorization] = "Basic UT------------------------------hcW5SV---------------------Qg=="; // Add Auth Token
string HtmlResult = wc.UploadString(URI, myParameters);
wc.Dispose();
var jobject = JsonConvert.DeserializeObject<Test>(HtmlResult);
string accessToken = jobject.access_token;
string relmid = "123412341234123421341234"; // Relmid
OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(accessToken);
ServiceContext serviceContext = new ServiceContext(relmid, IntuitServicesType.QBO, oauthValidator);
serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/";
//serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";//prod
serviceContext.IppConfiguration.MinorVersion.Qbo = "23";
CustomerCRUD.CustomerAddTestUsingoAuth(serviceContext);
CustomerCRUD.CustomerFindAllTestUsingoAuth(serviceContext);

How to pass body data with UploadStringAsync C#

I'm trying pass a string in the body of my POST request using WebClient class. Below is my code:
protected void GetAccessToken(string client_id, string secret)
{
var urlEncodedSecret = HttpUtility.UrlEncode(secret);
var urlEncodedSid = HttpUtility.UrlEncode(client_id);
string bodyData = String.Format("grant_type=client_credentials&client_id=ms-app%3a%2f%2f{0}&client_secret={1}&scope=notify.windows.com", client_id, secret);
string address = "https://login.live.com/accesstoken.srf";
string myParameters = "param1=value1&param2=value2&param3=value3";
Uri URI = new Uri(address);
System.Net.WebClient webClient = new WebClient();
webClient.BaseAddress = address;
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
webClient.Headers["Content-Length"] = "211";
webClient.Headers["Host"] = "https://login.live.com";
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(uploadStringCompleted);
webClient.UploadStringAsync(URI, "POST", bodyData);
}
private void uploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
string json = e.Result.ToString();
_oAuthToken = GetOAuthTokenFromJson(json);
}
When i run the application, i received the exception "The remote server returned an error: NotFound.".
I succeeded to make the same request using the Postman:
Anyone know something wrong about my request? Or something that puting me on a right way!?

Couldn't parse share document: error in LinkedIn REST API share

I try to call a share REST API with Hammock library function in my MVC 4 application.
Please see my code below
public ActionResult SharePost()
{
string content = "";
try
{
var credentials = new OAuthCredentials
{
ConsumerKey = "xxxxxxxxxxxxxx",
ConsumerSecret = "xxxxxxxxxxxxxxxx",
Token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
TokenSecret = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
Verifier = verifier,
Type = OAuthType.AccessToken,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
Version = "1.0"
};
var client = new RestClient { Authority = "http://api.linkedin.com/v1", Credentials = credentials, Method = WebMethod.Post };
var request = new RestRequest { Path = "/people/~/shares" };
StringBuilder sbAppend = new StringBuilder();
sbAppend.AppendLine("<?xml version=1.0 encoding=UTF-8?>");
sbAppend.AppendLine("<share><comment>Check out the LinkedIn Share API!</comment><content><title>LinkedIn Developers Documentation On Using the Share API</title><description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description><submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url><submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url></content><visibility><code>anyone</code></visibility></share>");
client.AddHeader("Content-Type", "text/xml");
byte[] msg = Encoding.Default.GetBytes(sbAppend.ToString());
client.AddPostContent(msg);
RestResponse response = client.Request(request);
content = response.Content;
}
catch (Exception ex)
{
throw ex;
}
return Content(content);
}
But i get a error responce.content
Edit
I use double quotes in my xml header. but always shows the same error.
Is there any thing wrong.
I didn't see the post xml values in fiddller. Please see this image
Please help.
I found error in your XML you are missing ""
Try this
sbAppend.AppendLine('<?xml version="1.0" encoding="UTF-8"?>');

How to connect Amazon API in c#

I have tried with below stuffs to connect Amazon API but failed to connect it I am getting error as "The remote server returned an error: (400) Bad Request". How to resolve this issue. Any help would be appreciated.
Code:
protected void btnAmazonItemSerach_Click(object sender, EventArgs e)
{
string associateId = "**************";
string accessKey = "*************";
string secretKey = "**************************";
string url = "http://webservices.amazon.com/onca/xml";
HttpWebRequest oRequest = (HttpWebRequest)HttpWebRequest.Create(url);
oRequest.Method = "GET";
oRequest.ContentType = "application/xml";
oRequest.Headers.Add("AWSAccessKeyId", accessKey);
oRequest.Headers.Add("AssociateTag", associateId);
oRequest.Headers.Add("Keywords", "Blueant s4");
oRequest.Headers.Add("Operation", "ItemSearch");
oRequest.Headers.Add("Service", "AWSECommerceService");
Encoding oEncod = new UTF8Encoding();
HMACSHA1 signature = new HMACSHA1();
signature.Key = oEncod.GetBytes(secretKey);
string sign = Convert.ToBase64String(signature.Key);
oRequest.Headers.Add("Signature", sign);
oRequest.Headers.Add("SearchIndex", "All");
oRequest.Headers.Add("Version", "2011-08-01");
string dateval = DateTime.Now.ToString();
oRequest.Headers.Add("Timestamp", dateval);
HttpWebResponse oResponse =(HttpWebResponse) oRequest.GetResponse();
StreamReader oreader =new StreamReader(oResponse.GetResponseStream());
var val = oreader.ReadToEnd();
XmlDocument oxmldoc = new XmlDocument();
oxmldoc.LoadXml(val);
XmlElement oxmlelem = (XmlElement)oxmldoc.GetElementsByTagName("Items")[0];
if (oxmlelem != null)
{
List<string> olistItems = new List<string>();
XmlNodeList olist = oxmldoc.GetElementsByTagName("Item");
for (int i = 0; i < olist.Count; i++)
{
string asi = olist[i].FirstChild.InnerText;
olistItems.Add(asi);
}
}
}

c# - How to Add Post Comment in LinkedIn?

I'm trying to add post comment in LinkedIn for the past one week
I've written this code
protected void Page_Load(object sender, EventArgs e)
{
string xmlContent = "<?xml version='1.0' encoding='UTF-8'?>";
xmlContent += "<comment><text>Check out</text></comment>";
byte[] databytes = Encoding.Default.GetBytes(xmlContent);
var credentials = new Hammock.Authentication.OAuth.OAuthCredentials
{
Type = OAuthType.AccessToken,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = "*********",
ConsumerSecret = "*********",
Token = "*********",
TokenSecret = "*********",
Version = "1.0"
};
var client = new Hammock.RestClient() { Authority = "http://api.linkedin.com/v1/posts" };
var request = new Hammock.RestRequest() { Path = "/56787878/comments", Method = Hammock.Web.WebMethod.Post, Timeout = new TimeSpan(0, 0, 5), Credentials = credentials };
request.AddHeader("Content-Type", "application/xml");
client.AddParameter("","");
client.AddPostContent(Encoding.UTF8.GetBytes(xmlContent));
//request.AddPostContent(Encoding.UTF8.GetBytes(xmlContent));
var response = client.Request(request);
Response.Write(response.Content);
}
I get an error in the below Xml format
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<error>
<status>400</status>
<timestamp>1374494502579</timestamp>
<request-id>QM4MYPEKJJ</request-id>
<error-code>0</error-code>
<message>Couldn't parse message document: error: Unexpected end of file after null</message>\n</error>
Anybody handle this error? Thanks in advance.

Categories

Resources