I'm using LinkedIn API to create posts. I also use the LinkedIn Mentions to create posts with mentions.
I can successfully create a post with mention except if I add in the message emojis or accents. Without mentions feature, I'm able to create any post with success.
Posts that work:
Hello Stackoverflow
Hello 😄 Stackoverflow
Hellóó Stackoverflow
Hello Stackoverflow (with mention to the linkedin page)
Posts that do not work:
Hello 🤣 Stackoverflow (with mention to the linkedin page)
Hellóó Stackoverflow (with mention to the linkedin page)
I receive the following error:
com.linkedin.content.common.ResponseException: share commentary is
invalid
I send the following data to LinkedIn:
array (
'author' => 'urn:li:organization:X',
'lifecycleState' => 'PUBLISHED',
'visibility' =>
array (
'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC',
),
'specificContent' =>
array (
'com.linkedin.ugc.ShareContent' =>
array (
'shareCommentary' =>
array (
'text' => 'Hellóó Stackoverflow',
'attributes' =>
array (
0 =>
array (
'length' => 13,
'start' => 8,
'value' =>
array (
'com.linkedin.common.CompanyAttributedEntity' =>
array (
'company' => 'urn:li:organization:X',
),
),
),
),
),
'shareMediaCategory' => 'NONE',
),
),
)
Solved.
Three issues needed to be fixed:
Switch from strpos to mb_strpos
Switch from strlen to mb_strlen
Count emojis in the body text as length 2, instead of 1
I'm now able to send text with accents, special chars & emojis with mentions.
Related
Using MailChimp API V3.0 to create a campaign.
I want to create a campaign that sends to users with a specific interest. It looks like this is possible in the docs, but I've tried every permutation I can think of. I can create the campaign fine as long as I leave out the segment_ops member. Does anyone have an example of PHP code that will do it?
It seems that interests are handled strangely since you don't include the interest-category when setting a users interests via the API. I'm not sure how this affects campaign creation.
I've gotten this to work, API definition can be found here https://us1.api.mailchimp.com/schema/3.0/Segments/Merge/InterestSegment.json
Interests have to be grouped under interest categories (called 'Groups' in some parts of the UI).
Here is the JSON for the segment_opts member of the recipients array:
"segment_opts": {
"match": "any",
"conditions": [{
"condition_type": "Interests",
"field": "interests-31f7aec0ec",
"op": "interestcontains",
"value": ["a9014571b8", "5e824ac953"]
}]
}
Here is the PHP array version with comments. The 'match' member refers to the the rules in the array of 'conditions'. The segment can match any, all, or none of the conditions. This example has only one condition, but others can be added as additional arrays in the 'conditions' array:
$segment_opts = array(
'match' => 'any', // or 'all' or 'none'
'conditions' => array (
array(
'condition_type' => 'Interests', // note capital I
'field' => 'interests-31f7aec0ec', // ID of interest category
// This ID is tricky: it is
// the string "interests-" +
// the ID of interest category
// that you get from MailChimp
// API (31f7aec0ec)
'op' => 'interestcontains', // or interestcontainsall, interestcontainsnone
'value' => array (
'a9014571b8', // ID of interest in that category
'5e824ac953' // ID of another interest in that category
)
)
)
);
You may also send to a Saved segment. The gotcha on this is that the segment_id has to be int. I was saving this value in a db as varchar, and it would not work unless cast to int.
(i am using use \DrewM\MailChimp\MailChimp;)
$segment_id = (int) $methodThatGetsMySegmentID;
$campaign = $MailChimp->post("campaigns", [
'type' => 'regular',
'recipients' => array(
'list_id' => 'abc123yourListID',
'segment_opts' => array(
'saved_segment_id' => $segment_id,
),
),
'settings' => array(
'subject_line' => 'A New Article was Posted',
'from_name' => 'From Name',
'reply_to' => 'info#example.com',
'title' => 'New Article Notification'
)
]);
is there a away to translate values in php using either google api translate or any other api...
<?php
// 1.- Query to get information
// 2.- build array with that query
// Example array from query
$data = array(
'0' => array (
'name' => 'Zapatos',
'color' => 'Verde'
),
'1' => array (
'name' => 'Casa',
'color' => 'Rosa'
),
);
// Now that the array has been build, lets make a translation
// Which I have no idea how to do that but the final array should be
$final = array(
'0' => array (
'name' => 'Zapatos',
'color' => 'Verde',
'name_en' => 'Shoes',
'color_en' => 'Green'
),
'1' => array (
'name' => 'Casa',
'color' => 'Rosa',
'name_en' => 'House',
'color_en' => 'Pink'
),
);
is this process possible or am I just dreaming?
I have very little knowledge on how exactly Goolge API works since I only use the Google Translate widget and the translation is after you present the information but in this case we need to make a translation before presenting the information...
Google translate API is a paid service. You need to get a api key from google api services :
google translate API
After that, you can make a curl to google api after getting your results from query :
sample url for curl :
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world&q=My%20name%20is%20Jeff
You will get the results as JSON object,do json_decode and add results to your array.
How to get Comments, Shares and Likes count of the post from linkedin Page using PHP
Using below code i posted posts on linkedIn Page,
include 'simplelinkedin.class.php';
$ln = new SimpleLinkedIn('ket', 'secret');
$ln->addScope('rw_nus');
if($ln->authorize()){
echo "<pre>";
print_r ($ln->fetch('POST','/v1/people/~/shares',
array(
'comment' => 'Hello Linkedin',
'content' => array(
'title' => 'test post',
'description' => 'test post comment ',
'submittedUrl' => 'http://www.google.com'
),
'visibility' => array('code' => 'anyone' )
)
));
}
for the above code i get key...
stdClass Object
(
[updateKey] => UNIU-103511686-5821126484735057920-SHARE
[updateUrl] => http://www.linkedin.com/updates?discuss=&scope=103511686&stype=M&topic=5821126484735057920&type=U&a=TpZB
)
Can anybody help me how to get Total Counts and Comments for the posts
Thanks!
Please refer to the following URL, I am using this for my ruby client and able to get likes and comments count using the API, when i pass the share ID.
API Reference - http://developer.linkedin.com/documents/commenting-reading-comments-and-likes-network-updates
Can anyone tell me how I can have an office phone automatically fill in a Contact when we select an Account name?
It should do that automatically. Look in /modules/Contacts/metadata/editviewdefs.php, and you should see the following.
array (
'name' => 'account_name',
'displayParams' =>
array (
'key' => 'billing',
'copy' => 'primary',
'billingKey' => 'primary',
'additionalFields' =>
array (
'phone_office' => 'phone_work',
),
),
i use version 5.3.3. I want to do the same thing with a small difference. when i am in an account and i want to create a quote, some information like billing address… transfer automatically but my custom field not…
I add in /modules/Accounts/metadata/editviewdefs.php this part of code:
2 =>
array (
0 =>
array (
‘name’ => ‘afm2_c’,
‘label’ => ‘LBL_AFM2’,
‘displayParams’ =>
array(
‘afm_timologisis_c’=> array(
‘name’ => ‘afm2_c’,
),
),
),
I want the value afm_timilogisis_c (quotes) to have the same value with afm2_c (accounts). That happens when i create a quote in an account with the address fields.
It doesn’t work with my custom fiels? Is anything false? Must i add this code in another folder-file? Must i change anything?
Thanks
I've looked at loads of forums about validation errors not showing and tried various things but to no avail...
Basically, the validation is correctly recognising the fields do not have values when they should, however the error messages don't 'automagically' appear below the input boxes.
Model validation rule is shown below:
var $validate = array(
'description' => array(
'rule' => 'notEmpty',
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a description of the change'
)
);
echo pr($this->data); output is shown below:
Array
(
[Change] => Array
(
[0] => Array
(
[id] => 3237
[cn_id] => 5132
[req_id] => 25
[description] =>
)
[1] => Array
(
[id] => 3238
[cn_id] => 5132
[req_id] => 22
[description] =>
)
[2] => Array
(
[id] => 3239
[cn_id] => 5132
[req_id] => 4
[description] =>
)
)
)
echo pr($this->Change->invalidFields()); output is shown below:
Array
(
[0] => Array
(
[description] => Please enter a description of the change
)
[1] => Array
(
[description] => Please enter a description of the change
)
[2] => Array
(
[description] => Please enter a description of the change
)
[description] => Please enter a description of the change
)
So, it is generating the errors messages for display, but they don't actually display in the view, and I don't know why?
Excerpt from the 'view' code is show below:
<?php echo $form->input('Change.'.$i.'.description',
array('value' => $cn['Change'][$i]['description'],
'label' => $engReq['Req']['description'])); ?>
Does anybody have ideas why the error messages are not showing?
I experienced the same issue with a hasMany model (where the form had numerically indexed fields) and came up with a validation solution that worked for me.
Quick answer: Before trying to actually save the data, I validated the data separately like (notice 'validate'=>'only'):
if($this->ModelName->saveAll($this->data, array('validate' => 'only'))) {
// proceed to save...
}
Doing it this way gave me the model's validation error message in the form, right under the input field that failed the validation (the normal Cake way of showing the validation error).
Note: I could not use saveAll() to actually save my data (I'll explain why in a minute). If I could use saveAll() to actually save the data, I could have gotten the validation at the same time as I saved by using (notice 'validate' => 'first'):
if($this->ModelName->saveAll($this->data, array('validate' => 'first')))
However, I could not use saveAll() to actually save the data, due to the fact that I needed to use a transaction to save several models at once, where some of the models were not directly related to other models. saveAll() will only save the model on which it is called, plus models directly related to it. Since Cake does not currently support nested transactions, and saveAll() uses one transaction automatically, I had to use save() on my models and start and end my transaction manually. However, this caused me to loose the validation message in my form on the hasMany items, even if I saved by using "$this->ModelName->save($this->data, array('validate'=>'first')".
Further explanation: The issue does seem to be related to using numerically indexed fields in the form. For example:
$this->Form->input("ModelName.0.field_name");
It seems this indexing scheme is the proper way to handle hasMany items in the form, but the validation messages would not find their way to this form input. It is interesting to notice that my view did in fact have access to the validation error. This can be seen in the view by using (notice no numerical index in these lines):
if($this->Form->isFieldError("ModelName.field_name")) {
echo $this->Form->error("ModelName.field_name");
}
Putting these lines after the '$this->Form->input("ModelName.0.field_name")' inserted a the validation message into the page, just not in the same div as the input field (and thus it didn't look ideal).
I couldn't figure out a way to tell Cake to use that validation message in the '$this->Form->input("ModelName.0.field_name")'. So I resorted to the 'validate' => 'only' method described earlier, which is working well for me.
shouldnt it be
var $validate = array(
'description' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a description of the change'
)
)
);
?