SDK Evernote PHP - Search for notes only within a given stack - evernote

I am using the evernote API to search for notes. I would like to know how to search for the notes only within a given stack.
At the moment I have the code below:
$client = new \Evernote\Client(config('app.evernote_token'), false);
$search = new \Evernote\Model\Search('ftp');
$notebook = null;
$scope = \Evernote\Client::SEARCH_SCOPE_NONE;
$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
$maxResult = 50;
$results = $client->findNotesWithSearch($search, $notebook, $scope, $order,
$maxResult);
print_r($results);

Resolved as follows:
$search = new \Evernote\Model\Search('stack:"Palavra-chave"');

Related

web scrape using simple html DOM parser

How to extract specific details like name and price of a product from Amazon platform using simple html DOM parser. for example: (product-image, name and price).
$httpClient = new \GuzzleHttp\Client();
$response = $httpClient->get('https://www.floridaleagueofcities.com/research-resources/municipal-directory/');
$htmlString = (string) $response->getBody();
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML($htmlString);
$xpath = new DOMXPath($doc);
$titles = $xpath->evaluate('//div[#class="accordion-body"]//ul//li/a');

Use elastica with PagerFanta and dynamic querybuilder

I have an application with symfony2 / doctrine 2 / elastica / fosElasticaBundle / pagerFanta.
I want to use a custom and dynamic queryBuilder in combination with pagerfanta and elastica. Not to transform the results but to prefilter them.
So far I was able to :
1. Use pagerfanta by itself with my custom queryBuilder :
$page = $request->get('page', 1);
$search = $request->get('search');
$querybuilder = $this->getDoctrine()->getRepository('AppBundle:FoodAnalytics\Recipe')->findByTopCategoryQueryBuilder($category);
$explorerManager = $this->get('explorer_manager');
$pagerFanta = $explorerManager->getPagerFanta($querybuilder, $page, 4);
$recipes = $pagerFanta->getCurrentPageResults();
Use Elastica with Pagerfanta but without my custom QueryBuilder :
$page = $request->get('page', 1);
$search = $request->get('search');
$finder = $this->container->get('fos_elastica.finder.website.recipe');
$pagerFanta = $finder->findPaginated($search);
$recipes = $pagerFanta->getCurrentPageResults();
Now, how can I also use my custom QueryBuilder ? I know you can set a custom one in elastica config but mine has to be dynamic = take an argument, so I'd like to set it in the controller. Is that possible ?
You can pass custom Elastica\Query to findPaginated method:
$query = new \Elastica\Query::create(new \Elastica\Query\Term(array(
'name' => $request->get('search')
));
$finder = $this->container->get('fos_elastica.finder.website.recipe');
$pagerFanta = $finder->findPaginated($query);
$recipes = $pagerFanta->getCurrentPageResults();
Maybe code is more clear and you can see how it works when you use just PagerFanta with ElasticaAdapter without FOSElasticaBundle:
// Searchable can be any valid searchable Elastica object. For example a Type or Index
$finder = new \Elastica\Index($elasticaClient, 'website.recipe');
// A Query can be any valid Elastica query (json, array, Query object)
$query = new \Elastica\Query::create(new \Elastica\Query\Term(array(
'name' => $request->get('search')
));
$elasticaAdapter = new \Pagerfanta\Adapter\ElasticaAdapter($finder, $query);
$paginator = new \Pagerfanta\Pagerfanta($elasticaAdapter);
$results = $paginator
->setMaxPerPage($limit)
->setCurrentPage($page)
->getCurrentPageResults();

How to get stats of multiple campaigns in Facebook ads api

I write the below code for retrieve single campaign stats.
$fields = array(
'start_time','actions','spent','clicks','impressions','end_time',
);
$params = array();
$campaign = new AdCampaign(123456);
$stats = $campaign->getStats($fields, $params);
here I can able to access the stats. But when use this function loop then I got issue like
Calling : $campaign = new AdCampaign($campaign_id);
Error : "An access token is required to request this resource"
But using graph API I can access the multiple campaigns stats at a time
https://graph.facebook.com/stats?ids=123,456,789&fields=start_time,actions,spent,clicks,impressions,end_time&access_token=...
I need it using Ads API .... Please solve it for me..
I think this is a missing feature from the SDK at the moment as you can only access stats relative to an object.
However, calling stats in a loop should not be a problem, assuming you instantiated the API class correctly.
use FacebookAds\Api;
use FacebookAds\Object\AdCampaign;
Api::init($app_id, $app_secret, $access_token);
$campaign_ids = array(...);
$fields = array(
'start_time',
'actions',
'spent',
'clicks',
'impressions',
'end_time',
);
$params = array();
$stats = array();
foreach($campaign_ids as $id) {
$campaign = new AdCampaign($id);
$stats[$id] = $campaign->getStats($fields, $params);
}
You could also just get all stats for all campaigns by using the getAdCampaignStats on AdAccount.

wordpress site integration with rest API

I'm trying to integrate with zoom.us, they have their guides here - https://support.zoom.us/hc/en-us/articles/201363053-Meeting-API
When someone schedules a meeting, the scheduler creates a post, which I pick up and call this function:
function scheduler_zoom_integration($post_id) {
$postdata = get_post($post_id);
$appointment_id = get_post_meta( $post_id, '_birs_appointment_id', true );
if (!empty($appointment_id)) {
$conference_details = schedule_meeting();
add_post_meta($appointment_id,'appointment_zoom_details', $conference_details, true);
}
}
add_action('publish_post', 'scheduler_zoom_integration');
Inside that function I call the schedule_meeting function that is using the REST API from zoom to get the meeting details including the link people will click to join the meeting.
function schedule_meeting($coach_id, $appointment_id, $start_time) {
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxx';
$api_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$coach_zoom_id = get_user_meta($coach_id, 'coachzoomid', true);
$url = 'https://api.zoom.us/v1/meeting/create?api_key='.$api_key.'&api_secret='.$api_secret.'&data_type=JSON&host_id='.$coach_zoom_id.'&topic=health&type=2&start_time='.$start_time.'&duration=30&timezone=GMT-7:00&option_jbh=true&option_start_type=video';
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$response = fopen($url, 'r', false, $context);
fpassthru($response);
$response = json_decode($response);
fclose($response);
return $response;
}
I'm looking to get feedback on how I'm performing this function as I've never done a REST API before. Should I use fopen / fclose? How do I make the call to begin with? Any help is appreciated.
You should try using WordPress' built in HTTP API. It has helper functions for doing HTTP calls. I see you're doing a GET so check out:
http://codex.wordpress.org/Function_Reference/wp_remote_get
Note that it returns WP_Error class on failure.

Drupal 7 - Insert taxonomy into node object

I have a script which successfully creates new nodes. But I'm having trouble setting the taxonomy before saving.
I believe in Drupal 6 I would use this method.
$cat1_tid = taxonomy_get_term_by_name($data[$i]['cat1']);
$cat2_tid = taxonomy_get_term_by_name($data[$i]['cat2']);
$cat3_tid = taxonomy_get_term_by_name($data[$i]['cat3']);
$node->taxonomy = array($cat1_tid, $cat2_tid, $cat3_tid);
I think in Drupal 7 I would do this (my field name is Catalog)
$node->taxonomy_catalog['und'][0] = array($term1Obj, $term2Obj);
taxonomy_get_term_by_name doesn't seem to return the correct object to insert into the node object.
If anyone can shed some light, appreciated.
Thanks
EDIT
Solution:
// Taxonomy
$categories = array($data[$i]['cat1'], $data[$i]['cat2'], $data[$i]['cat3']);
foreach ($categories as $key => $category) {
if ($term = taxonomy_get_term_by_name($category)) {
$terms_array = array_keys($term);
$node->taxonomy_catalog[LANGUAGE_NONE][$key]['tid'] = $terms_array['0'];
}
}
Below is some quick-and-dirty code I used recently to import "command" nodes into a site. Mid-way down, the foreach loop takes care of creating and assigning terms, as needed.
$command = new stdClass;
$command->language = LANGUAGE_NONE;
$command->uid = 1;
$command->type = 'drubnub';
$command->title = $line['0'];
$command->body[LANGUAGE_NONE]['0']['value'] = $line['1'];
$command->url[LANGUAGE_NONE]['0']['value'] = trim($line['2']);
$command->uses[LANGUAGE_NONE]['0']['value'] = $line['3'];
$tags = explode(',', $line['4']);
foreach ($tags as $key => $tag) {
if ($term = taxonomy_get_term_by_name($tag)) {
$terms_array = array_keys($term);
$command->field_tags[LANGUAGE_NONE][$key]['tid'] = $terms_array['0'];
} else {
$term = new STDClass();
$term->name = $tag;
$term->vid = 1;
if (!empty($term->name)) {
$test = taxonomy_term_save($term);
$term = taxonomy_get_term_by_name($tag);
foreach($term as $term_id){
$command->product_tags[LANGUAGE_NONE][$key]['tid'] = $term_id->tid;
}
$command->field_tags[LANGUAGE_NONE][$key]['tid'] = $tid;
}
}
}
node_save($command);
Here you are, this code successfully add a new term to the node before the node is created.
$my_term_name = 'micky';
$term_array = taxonomy_get_term_by_name($my_term_name);
if($term_array == array()){
//empty term ..
$term->name = $my_term_name;
$term->vid = 1;
taxonomy_term_save($term);
$term_array = taxonomy_get_term_by_name($my_term_name);
}
//get the first index of the array .
foreach ($term_array as $tid => $term_object)break;
$node->field_tag['und'][$tid] = (array)$term_object;
Perhaps my experience is unique, but I found that using
$term = taxonomy_get_term_by_name($tag)
$tid = $term->tid;
caused an error.
I found that after $term is saved, there is no need to fetch the newly created term.
The $term object is updated to include the new tid.
Any answer that use LANGUAGE_NONE or 'und' to alter a field is not the proper way of doing it as it assumes that the drupal site is one language. The proper way to edit a field is to use entity_metadata_wrapper.
$node_wrapper = entity_metadata_wrapper('node', $node);
// If you have Entity API [entity] module installed you can simply.
$node_wrapper = $node->wrapper();
// It is good practice to check the terms in the field before adding
// a new one to make sure that the term is not already set.
$term_ids_current = $node_wrapper->taxonomy_catalog->raw();
if (!in_array($term_new_id, $term_ids_current)) {
$node_wrapper->taxonomy_catalog[] = $term_new_id;
}
// To add multiple terms iterate an array or terms ids.
$term_ids_current = $node_wrapper->taxonomy_catalog->raw();
$tern_new_ids = array(1, 2, 3);
foreach ($term_new_ids as $term_new_id) {
if (!in_array($term_new_id, $term_ids_current)) {
$node_wrapper->taxonomy_catalog[] = $term_new_id;
}
}
// To remove a term.
$term_ids_current = $node_wrapper->taxonomy_catalog->raw();
$delta = array_search($term_remove_id, $term_ids_current);
if (is_int($delta)) {
$node_wrapper->taxonomy_catalog->offsetUnset($delta);
}
// To replace all terms.
$term_new_ids = array(1, 2, 3);
$node_wrapper->taxonomy_catalog->set($term_new_ids);
// To get all the fully loaded terms in a field.
$terms = $node_wrapper->taxonomy_catalog->value();
// At the end make sure to save it.
$node_wrapper->save();

Resources