Unknown authentication scheme when liking post (LinkedIn API) - linkedin

Below goal is to like a post!
I get an error when trying to "Like" a post with the REST API (LinkedIn)
I have created an accesstoken with all scopes:
scope=w_messages+rw_company_admin+rw_nus+r_emailaddress+r_basicprofile+rw_groups+r_fullprofile+r_network+r_contactinfo
I can retreive comments from posts with the accesstoken which tell us that I have set it up correctly as a base.
However when I try to like a comment with the below code (just after in the same code where I have collected a comment), I receive this error:
"unknown authentication scheme"
I wonder why I can't like a post when I have set all scopes and I also have them checked in my application settings. Also notice that the postID is correct as I can retreive the comments for the post?
Thank you!
String accessToken = "MYLONGTOKEN"; //Just dummy example
String postID = "g-123456-S-123456789"; //Just dummy example
String requestUrl = "https://api.linkedin.com/v1/posts/" + postID + "/relation-to-viewer/is-liked&oauth2_access_token=" + accessToken;
RestSharp.RestClient rc = new RestSharp.RestClient();
RestSharp.RestRequest request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.PUT);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-li-format", "json");
request.RequestFormat = RestSharp.DataFormat.Json;
restResponse = (RestSharp.RestResponse)rc.Execute(request);
responseStatus = restResponse.ResponseStatus;
//unknown authentication scheme
MessageBox.Show(restResponse.Content.ToString());

I found a solution which seems to work. The additional and replacement code is:
//Comment this post
requestUrl = "https://api.linkedin.com/v1/posts/" + postID + "/comments?oauth2_access_token=" + accessToken;
var comment = new
{
text = "This is a comment!"
};
rc = new RestSharp.RestClient();
request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-li-format", "json");
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddBody(comment);
restResponse = (RestSharp.RestResponse)rc.Execute(request);
responseStatus = restResponse.ResponseStatus;
MessageBox.Show(responseStatus.ToString() + "," + restResponse.Content.ToString());

Related

How to write to csv file and attach it to email using Mail kit - Dotnet 6.0?

I want to know how to write my response - filtered Response to a csv file and attach it to an email using Mail kit. I can send an email with a body but I am unable to add an attachment.
//My Object
var result = await _thunderheadReportRepository.GetMembershipOfferDetailsAsync(searchDate, cancellationToken);
var filteredResponse = result.Select(o => new MembershipOfferDetailsResponse { CreationDate = o.CreationDate!, CorrelationId = o.CorrelationId!, PolicyCode = o.PolicyCode!, AnnualPremium = o.AnnualPremium! }).ToList();
return filteredResponse;
//My email body
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("email", _appSettings.EmailConfiguration.From));
emailMessage.To.AddRange(message.To);
emailMessage.Subject = message.Subject;
var bodybuilder = new BodyBuilder { HtmlBody = string.Format("<h2 style='color:red'>{0}</h2>", message.Content) };
emailMessage.Body = bodybuilder.ToMessageBody();
return emailMessage;
You just need to call:
bodyBuilder.Attachments.Add ("filename.csv");

Notification hub device registration with installation

After reading this I've been trying to create an installation in my xamarin.android app but I keep getting an 'Unauthorized error' I feel that I'm missing something. Any help is appreciated.
Previously I was able to register with the hub using
var regID = hub.Register(token, tags.ToArray()).RegistrationId;
so I'm sure my hub has been setup correctly and that I am using the correct connectionstring.
My installation object
install.installationId = installationId; //guid
install.tags = Tags;
install.platform = "gcm";
install.pushChannel = token; //refresh token from fcm
Call to Create installation
private async Task<HttpStatusCode> CreateOrUpdateInstallationAsync(DeviceInstallation deviceInstallation,
string hubName, string listenConnectionString)
{
if (deviceInstallation.installationId == null)
return HttpStatusCode.BadRequest;
// Parse connection string (https://msdn.microsoft.com/library/azure/dn495627.aspx)
ConnectionStringUtility connectionSaSUtil = new ConnectionStringUtility(listenConnectionString);
string hubResource = "installations/" + deviceInstallation.installationId + "?";
string apiVersion = "api-version=2015-04";
// Determine the targetUri that we will sign
string uri = connectionSaSUtil.Endpoint + hubName + "/" + hubResource + apiVersion;
//=== Generate SaS Security Token for Authorization header ===
// See, https://msdn.microsoft.com/library/azure/dn495627.aspx
string SasToken = connectionSaSUtil.getSaSToken(uri, 60);
using (var httpClient = new HttpClient())
{
string json = JsonConvert.SerializeObject(deviceInstallation);
httpClient.DefaultRequestHeaders.Add("Authorization", SasToken);
var response = await httpClient.PutAsync(uri, new StringContent(json, System.Text.Encoding.UTF8, "application/json"));
return response.StatusCode;
}
}

PayPal integration - Error #2096 in Flex Mobile

So i am trying to integrate PayPal in my Flex Mobile app. I make my first call like this:
(keys are sandbox by paypal dev resources)
protected function getPaypal():void {
var client_id:String="EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp";
var secret:String="EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp";
var params:Object = new Object();
params.grant_type="client_credentials";
var encoder:Base64Encoder = new Base64Encoder();
encoder.encode(client_id + ":" + secret);
//var s:String = JSON.stringify(params);
paypal.contentType = "application/x-www-form-urlencoded";
paypal.headers["Authorization"] = "Basic " + encoder.toString();
paypal.method = "POST";
paypal.url = "https://api.sandbox.paypal.com/v1/oauth2/token";
paypal.send(params);
}
This fails and returns the following:
'Error #2096: The HTTP request header Basic RU9KMlMtWjZPb05fbGVfS1MxZDc1d3NaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA6RUNsdXNNRVVrOGU5
aWhJN1pkVkxGNWNaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA= cannot be set via ActionScript.' faultDetail:'null'
I can't figure out what seems to be the problem.
Any help?
Maybe this?
https://stackoverflow.com/a/539173/3384609
Gist:
You can fix this by setting (in the above example)
encoder.insertNewLines = false; The default setting is true.

Follow Company issue (LinkedIn API)

I am trying to follow a company without success.
I have generated an access token for all scopes which also works for other functions with the API:
scope=w_messages+rw_company_admin+rw_nus+r_emailaddress+r_basicprofile+rw_groups+r_fullprofile+r_network+r_contactinfo
The below code reaches the end and shows the MessageBox with message:
"BadRequest,Can not parse JSON company document.\nRequest body:\n\nError:\nnull"
I will be happy for help. I have follwed the below documentation but it doesn't exactly show how to follow the company, so it leaves me with this question and example below:
https://developer.linkedin.com/documents/company-follow-and-suggestions
String companyID = "9288340";
requestUrl = "https://api.linkedin.com/v1/people/~/following/companies/id=" + companyID + "?oauth2_access_token=MYTOKENGOESHERE";
RestSharp.RestClient rc = new RestSharp.RestClient();
RestSharp.RestRequest request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST); //POST = Follow
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-li-format", "json");
request.RequestFormat = RestSharp.DataFormat.Json;
RestSharp.RestResponse restResponse = (RestSharp.RestResponse)rc.Execute(request);
RestSharp.ResponseStatus responseStatus = restResponse.ResponseStatus;
MessageBox.Show(restResponse.StatusCode.ToString() + "," + restResponse.Content.ToString());
After a lot of testing, I just managed to be able to follow a company.
So the below code is working:
requestUrl = "https://api.linkedin.com/v1/people/~/following/companies?oauth2_access_token=MYTOKENGOESHERE";
var BODY = new
{
id = "9288340" //companyID
};
RestSharp.RestClient rc = new RestSharp.RestClient();
RestSharp.RestRequest request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST); //POST = Follow
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-li-format", "json");
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddBody(BODY);
RestSharp.RestResponse restResponse = (RestSharp.RestResponse)rc.Execute(request);
RestSharp.ResponseStatus responseStatus = restResponse.ResponseStatus;
MessageBox.Show(restResponse.StatusCode.ToString() + "," + restResponse.Content.ToString());

Using the Tridion UGC web service to add ratings

I know I can add comments through the UGC web service by using something like the following:-
WebServiceClient ugcCall = new WebServiceClient();
string ugcData = "{ \"d\" :{\"Content\":\"" + comment + "\",\"Status\":2,\"ItemPublicationId\":\"" + PublicationId + "\",\"ItemId\":\"" + itemid + "\",\"ItemType\":\"16\",\"Id\":0,\"ModeratedDate\":\"\",\"LastModifiedDate\":\"\",\"CreationDate\":\"\",\"Score\":0,\"Moderator\":\"\",\"User\":{\"Id\":\"ACME%5Cjbloggs\",\"Name\":\"Joe Bloggs\"}}}";
string result = ugcCall.UploadString("/Comments", "POST", ugcData);
My question is what is the syntax for adding ratings and likes and dislikes? Is this documented anywhere?
MTIA
John
The command for uploading ratings is '/Ratings' instead of '/Comments'. The JSON is different too, of course. In the code below, I don't write out the JSON manually, instead I construct a simple Rating object and use the JavascriptSerializer to convert it to JSON:
TcmUri tcmUri = new TcmUri(itemUri);
WSR_ContentDelivery.User user = new WSR_ContentDelivery.User { Id = GetUserId() };
WSR_ContentDelivery.Rating rating = new WSR_ContentDelivery.Rating
{
CreationDate = DateTime.UtcNow,
LastModifiedDate = DateTime.UtcNow,
ItemPublicationId = tcmUri.PublicationId,
ItemId = tcmUri.ItemId,
ItemType = tcmUri.ItemTypeId,
RatingValue = ratingValue.ToString(),
User = user,
Id = "0"
};
JavaScriptSerializer oSerializer = new JavaScriptSerializer();
WSClient.UploadString("/Ratings", "POST", "{d:" + oSerializer.Serialize(rating) + "}", GetUserId());

Resources