Evernote API findNotesMetadata php - php

I am trying to retrieve a list of notes from the Evernote API, and the script I am using returns a screen that says "whoops something went wrong"
<?php
$token = 'S=s1:U=904d8:E=152a2ea0df7:C=14b4b38e1d0:P=1cd:A=en-devtoken:V=2:H=c28ff07ca3ee987b8c916cfc0c536e99';
$sandbox = true;
$client = new \Evernote\Client($token, $sandbox);
$notebookGuid = "c1977c63-ffc7-4876-a071-67fd6ea9fd4c";
$filter = new NoteFilter();
// $filter->notebookGuid = $notebookGuid;
$offset = 0;
$spec = new NotesMetadataResultSpec();
$spec->includeTitle = true;
$spec->includeContentLength = true;
$spec->includeCreated = true;
$spec->includeUpdated = true;
//$spec->includeDeleted = true;
$spec->includeUpdateSequenceNum = true;
$spec->includeNotebookGuid = true;
$spec->includeTagGuids = true;
$spec->includeAttributes = true;
$spec->includeLargestResourceMime = true;
$spec->includeLargestResourceSize = true;
// $resultSpec->includeTitle = true;
$notes = $client->findNotesMetadata($token, $filter, 0, 10,$spec);

First, I think you should comment out the line where you assign the notebookGuid to filter.
Second, findNotesMetadata is a method of a NoteStore object.
So, the last lines should look like that:
$noteStore = $client->getNoteStore();
$notes = $noteStore->findNotesMetadata($token, $filter, 0, 10, $spec);

Related

: Invalid argument supplied for foreach() in

tried this code on two different WordPress sites. It was working on the first site. After I moved the template completely to my new site, I got this error: Invalid argument supplied for foreach() in
I do not know what is the reason, although it is the same template, plugins and everything
<?php
$novoteste = new ComicLatestChapters("6", "6");
$resultados = $novoteste->filter;
foreach($resultados as $resultado => $novoteste) {
$series_id = $novoteste->post_id;
$status = get_post_status($series_id);
if($status !== 'publish' || $series_id == 20305){
continue;
}
$result = get_post($resultado);
$sort_by = $sort_setting['sortBy'];
$sort_order = $sort_setting['sort'];
$chapters = $wp_manga_functions->get_latest_chapters($series_id, null, 2, 0, $sort_by, $sort_order);
$latest_chapter = $chapters[0];
$semilatest_chapter = $chapters[1];
$scheduled1 = $latest_chapter['schedule_time'];
$scheduled2 = $semilatest_chapter['schedule_time'];
$series_link = get_the_permalink($series_id);
$chapter_slug1 = $latest_chapter['chapter_slug'];
$chapter_slug2 = $semilatest_chapter['chapter_slug'];
$type = $wp_manga_functions->get_manga_type( $manga_id );
$chapter_name1 = $latest_chapter['chapter_name'];
$chapter_name2 = $semilatest_chapter['chapter_name'];
$mass_released = is_mass_released($series_id);
$ch_1 = get_only_numbers($chapter_name1);
$ch_2 = get_only_numbers($chapter_name2);
$rating = get_post_meta($series_id, '_manga_avarage_reviews', true);
$chapter_index1 = $latest_chapter['chapter_index'];
$chapter_index2 = $semilatest_chapter['chapter_index'];
$link1 = $wp_manga_functions->build_chapter_url($series_id, $chapter_slug1);
$link2 = $wp_manga_functions->build_chapter_url($series_id, $chapter_slug2);
$restored = get_post_meta($series_id, 'restored', true);
$publish = $latest_chapter['date'];
$publish2 = $semilatest_chapter['date'];
$type = get_post_meta($series_id, '_wp_manga_chapter_type', true);
$series_status = get_post_meta($series_id, '_wp_manga_status', true);
if (isset($scheduled1)){
$published = $wp_manga_functions->get_time_diff($scheduled1);}
else{
$published = $wp_manga_functions->get_time_diff($publish);
}
if (isset($scheduled2)){
$published2 = $wp_manga_functions->get_time_diff($scheduled2);}
else{
$published2 = $wp_manga_functions->get_time_diff($publish2);
}
$series_class = get_post_meta($series_id, 'manga_custom_badges', true);
$class_css = str_replace(' ', '-', strtolower($series_class));
$novel1 = get_post($series_id);
$title = $novel1->post_title;
$description = $result->post_content;
$thumbnail_id = get_post_meta($series_id, '_thumbnail_id', true);
$thumbnail_link = get_the_post_thumbnail_url($series_id, array(290,395));
?>
You should check that the output $resultados = $novoteste->filter; Is it empty or not?
The code changes like this:
<?php
$novoteste = new ComicLatestChapters( "6", "6" );
$resultados = $novoteste->filter ?: array();
foreach( $resultados as $resultado => $novoteste ) {
........
}

how to use dreamscape api in nodejs for check domain name

I have already work this in php. Here is my working code:
$request = array(
'DomainNames' => $domain_names
);
$response = dreamScapeAPI('DomainCheck', $request);
$available = false;
$alt_domains = array(); // Alternative to user's expected domain names
if (!is_soap_fault($response)) {
// Successfully checked the availability of the domains
if (isset($response->APIResponse->AvailabilityList)) {
$availabilityList = $response->APIResponse->AvailabilityList;
foreach ($availabilityList as $list) {
if ($list->Available){
if ($domain == $list->Item) {
$available = true; // user prefered domain found
}
else {
$alt_domains[] = $list->Item;
}
}
}
}
else {
$error = $response->APIResponse->Errors;
foreach ($error as $e) {
$api_error = $e->Message;
//echo $e->Item . ' - ' . $e->Message . '<br />';
}
}
}
function dreamScapeAPI($method, $data = null) {
$reseller_api_soap_client = "";
$soap_location = 'http://soap.secureapi.com.au/API-2.1';
$wsdl_location = 'http://soap.secureapi.com.au/wsdl/API-2.1.wsdl';
$authenticate = array();
$authenticate['AuthenticateRequest'] = array();
$authenticate['AuthenticateRequest']['ResellerID'] = '**';
$authenticate['AuthenticateRequest']['APIKey'] = '**';
//convert $authenticate to a soap variable
$authenticate['AuthenticateRequest'] = new SoapVar($authenticate['AuthenticateRequest'], SOAP_ENC_OBJECT);
$authenticate = new SoapVar($authenticate, SOAP_ENC_OBJECT);
$header = new SoapHeader($soap_location, 'Authenticate', $authenticate, false);
$reseller_api_soap_client = new SoapClient($wsdl_location, array('soap_version' => SOAP_1_2, 'cache_wsdl' => WSDL_CACHE_NONE));
$reseller_api_soap_client->__setSoapHeaders(array($header));
$prepared_data = $data != null ? array($data) : array();
try {
$response = $reseller_api_soap_client->__soapCall($method, $prepared_data);
} catch (SoapFault $response) { }
return $response;
}
I tried with this : https://github.com/dan-power/node-dreamscape
But domain search can not work properly. Mainly, I want it on nodejs using nodejs dreamscape api but this method is not available on nodejs.
Here is my working demo: click here

How to create pagination in shopify rest api using php

I created curl in php for use shopify product rest API. Now I want to create pagination in that.
How to create?
Link: "<https://{shop}.myshopify.com/admin/api/{version}/products.json?page_info={page_info}&limit={limit}>; rel={next}, <https://{shop}.myshopify.com/admin/api/{version}/products.json?page_info={page_info}&limit={limit}>; rel={previous}"
How to use Link ?
Thanks
Below function can help you. to fetch data using API in Php/Laravel
public function request($method,$url,$param = []){
$client = new \GuzzleHttp\Client();
$url = 'https://'.$this->username.':'.$this->password.'#'.$this->domain.'/admin/api/2019-10/'.$url;
$parameters = [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json'
]
];
if(!empty($param)){ $parameters['json'] = $param;}
$response = $client->request($method, $url,$parameters);
$responseHeaders = $response->getHeaders();
$tokenType = 'next';
if(array_key_exists('Link',$responseHeaders)){
$link = $responseHeaders['Link'][0];
$tokenType = strpos($link,'rel="next') !== false ? "next" : "previous";
$tobeReplace = ["<",">",'rel="next"',";",'rel="previous"'];
$tobeReplaceWith = ["","","",""];
parse_str(parse_url(str_replace($tobeReplace,$tobeReplaceWith,$link),PHP_URL_QUERY),$op);
$pageToken = trim($op['page_info']);
}
$rateLimit = explode('/', $responseHeaders["X-Shopify-Shop-Api-Call-Limit"][0]);
$usedLimitPercentage = (100*$rateLimit[0])/$rateLimit[1];
if($usedLimitPercentage > 95){sleep(5);}
$responseBody = json_decode($response->getBody(),true);
$r['resource'] = (is_array($responseBody) && count($responseBody) > 0) ? array_shift($responseBody) : $responseBody;
$r[$tokenType]['page_token'] = isset($pageToken) ? $pageToken : null;
return $r;
}
Example usage of this function
$product_ids = [];
$nextPageToken = null;
do{
$response = $shop->request('get','products.json?limit=250&page_info='.$nextPageToken);
foreach($response['resource'] as $product){
array_push($product_ids, $product['id']);
}
$nextPageToken = $response['next']['page_token'] ?? null;
}while($nextPageToken != null);
If you want to use graphQL api in php / laravel then below post can help you
How to request shopify graphql-admin-api from an api?
As of API version 2019-07 you do indeed need to use cursor based pagination.
First make a normal API call, include the header response.
Then in the header response you will see link : ... with rel next or previous.
Extract the page_info and then make another call with page_info.
The first call is something like this:
https://...:...#xyz.myshopify.com/admin/api/2019-10/products.json?limit=2&published_status=published
Then the second call is
https://...:...#xyz.myshopify.com/admin/api/2019-10/products.json?limit=2&page_info=asdfas1321asdf3as1f651saf61s3f1x32v1akjhfasdj
When you make the second call, remove any filers as the filters will be applied from the first call.
Btw: if your testing in a browser due to the way the link is in angle brackets, it will be hidden, so just view source code in your developer environment.
Reference: https://help.shopify.com/en/api/guides/paginated-rest-results
private $shop_url = '';
private $shop_user = '';
private $shop_password = '';
function __construct($shop) {
$this->shop_url = $shop->url;
$this->shop_user = $shop->user;
$this->shop_password = $shop->userpas;
$this->syncShopifyOrder($shop);
}
private function getOrderRequest($url){
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url, [
'auth' => [$this->shop_user, $this->shop_password]
]);
if($response->getStatusCode() !== 200){
throw new OrderSyncException('Connection problem!');
}
$data = [];
$paginate_links = $response->getHeader('Link');
if($paginate_links){
$page_link = $paginate_links[0];
$links_arr = explode(",", $page_link);
if($links_arr){
$tobeReplace = ["<",">",'rel="next"',";",'rel="previous"'];
$tobeReplaceWith = ["","","",""];
foreach ($links_arr as $link) {
$link_type = strpos($link, 'rel="next') !== false ? "next" : "previous";
parse_str(parse_url(str_replace($tobeReplace, $tobeReplaceWith, $link), PHP_URL_QUERY), $op);
$data[$link_type] = trim($op['page_info']);
}
}
}
$order_data = $response->getBody()->getContents();
$data['all_orders'] = (json_decode($order_data))->orders;
return $data;
}
// Shopify Orders
private function syncShopifyOrder($shop)
{
$count = 0;
try{
if($shop){
$nextPageToken = null;
do{
$param = ($nextPageToken)? '&page_info='.$nextPageToken : '&status=any&fulfillment_status=any&order=created_at asc&created_at_min=2020-08-10T13:30:33+02:00';
$url = $this->shop_url . 'admin/api/2020-01/orders.json?limit=250'.$param;
$data = $this->getOrderRequest($url);
$all_orders = $data['all_orders'];
$nextPageToken = isset($data['next']) ? $data['next'] : null;
if($all_orders){
$count += count((array) $all_orders);
$this->bulkorderInsertShopify($shop, $all_orders);
}
}while($nextPageToken);
}else{
throw new OrderSyncException('You have not configured shop!');
}
$this->syncSuccessReport($shop, $count);
}catch(OrderSyncException $e) {
$this->syncErrorReport($shop, $count, $e->getMessage());
}catch(\Exception $e) {
$this->syncErrorReportAdmin($shop, $count, $e);
}
}

i'm a beginner in laravel and i have an issue with passing a variable from if to else , very very strange

Please someone help me :( and sorry for these beginner problem , its really strange , $stdobj works completely fine when it is in auth and first elseif , and strange thing is that second elseif has exactly the same code , but retunes laravel error Trying to get property of non-object . but it works in first elseif , why it says it is not an object in the last one !!!
$our_user = User::check_if_user_matches($username);
$stdobj = new \stdClass();
$stdobj = $our_user['usid'];
if (\Auth::attempt(['username' => $username, 'password' => $password])) {
$logdata = [];
$v = new Verta();
$logdata['logTime'] = $v->formatTime();
$logdata['logDate'] = $v->formatDate();
$logdata['logCode'] = '001';
$logdata['user_id'] = $stdobj->id;
$logs->insert($logdata);
return redirect()->intended('home');
} elseif ($our_user['usname'] == $username) {
$v = new Verta();
//$stdobj1 = $our_user['usid'];
$logdata = [];
$logdata['logTime'] = $v->formatTime();
$logdata['logDate'] = $v->formatDate();
$logdata['logCode'] = '003';
$logdata['user_id'] = $stdobj->id;
$logs->insert($logdata);
return redirect()->intended('login');
} elseif ($our_user['usname'] != $username) {
$v = new Verta();
//$stdobj1 = $our_user['usid'];
$logdata = [];
$logdata['logTime'] = $v->formatTime();
$logdata['logDate'] = $v->formatDate();
$logdata['logCode'] = '002';
$logdata['user_id'] = $stdobj->id;
$logs->insert($logdata);
return redirect()->intended('login');
} else {
return back()->withInput();
}
You need to assign value to your obejct. Add this line at top-
$stdobj1 = new \stdClass();
$stdobj1->id = $our_user['usid'];;
because it can't get the password , when there is no username . and you can find a password and compare it to the one in the database , this way :
$passes = \DB::table('users')->pluck('password');
foreach ($passes as $pass) {
if(\Hash::check($password, $pass)) {
$this_user_pass = $pass;
return view('MainPages.example',['pass' => $this_user_pass]);
}
}

Creating default object from empty value ( stdClass? )

The script run good, but only when I fetching out the groups of the user, it's says:
SteamUser.php (132): Creating default object from empty value
function getProfileData() {
//Set Base URL for the query:
if(empty($this->vanityURL)) {
$base = "http://steamcommunity.com/profiles/{$this->userID}/?xml=1";
} else {
$base = "http://steamcommunity.com/id/{$this->vanityURL}/?xml=1";
}
try {
$content = SteamUtility::fetchURL($base);
if ($content) {
$parsedData = new SimpleXMLElement($content);
} else {
return null;
}
} catch (Exception $e) {
//echo "Whoops! Something went wrong!\n\nException Info:\n" . $e . "\n\n";
return null;
}
if(!empty($parsedData)) {
$this->steamID64 = (string)$parsedData->steamID64;
$this->steamID = (string)$parsedData->steamID;
$this->stateMessage = (string)$parsedData->stateMessage;
$this->visibilityState = (int)$parsedData->visibilityState;
$this->privacyState = (string)$parsedData->privacyState;
$this->avatarIcon = (string)$parsedData->avatarIcon;
$this->avatarMedium = (string)$parsedData->avatarMedium;
$this->avatarFull = (string)$parsedData->avatarFull;
$this->vacBanned = (int)$parsedData->vacBanned;
$this->tradeBanState = (string)$parsedData->tradeBanState;
$this->isLimitedAccount = (string)$parsedData->isLimitedAccount;
$this->onlineState = (string)$parsedData->onlineState;
$this->inGameServerIP = (string)$parsedData->inGameServerIP;
//If their account is public, get that info:
if($this->privacyState == "public") {
$this->customURL = (string)$parsedData->customURL;
$this->memberSince = (string)$parsedData->memberSince;
$this->steamRating = (float)$parsedData->steamRating;
$this->hoursPlayed2Wk = (float)$parsedData->hoursPlayed2Wk;
$this->headline = (string)$parsedData->headline;
$this->location = (string)$parsedData->location;
$this->realname = (string)$parsedData->realname;
$this->summary = (string)$parsedData->summary;
}
//If they're in a game, grab that info:
if($this->onlineState == "in-game") {
$this->inGameInfo = array();
$this->inGameInfo["gameName"] = (string)$parsedData->inGameInfo->gameName;
$this->inGameInfo["gameLink"] = (string)$parsedData->inGameInfo->gameLink;
$this->inGameInfo["gameIcon"] = (string)$parsedData->inGameInfo->gameIcon;
$this->inGameInfo["gameLogo"] = (string)$parsedData->inGameInfo->gameLogo;
$this->inGameInfo["gameLogoSmall"] = (string)$parsedData->inGameInfo->gameLogoSmall;
}
//Any weblinks listed in their profile:
if(!empty($parsedData->weblinks)) {
$this->weblinks = array();
$i = 0;
foreach ($parsedData->weblinks->weblink as $weblink) {
$this->weblinks[$i]->title = (string)$weblink->title;
$this->weblinks[$i]->link = (string)$weblink->link;
$i++;
}
}
if(!empty($parsedData->groups)) {
$this->groups = array();
$i = 0;
foreach ($parsedData->groups->group as $group) {
$this->groups[$i]->groupID64 = (string)$group->groupID64; // row 132 in script
$this->groups[$i]->groupName = (string)$group->groupName;
$this->groups[$i]->groupURL = (string)$group->groupURL;
$this->groups[$i]->headline = (string)$group->headline;
$this->groups[$i]->summary = (string)$group->summary;
$this->groups[$i]->avatarIcon = (string)$group->avatarIcon;
$this->groups[$i]->avatarMedium = (string)$group->avatarMedium;
$this->groups[$i]->avatarFull = (string)$group->avatarFull;
$this->groups[$i]->memberCount = (string)$group->memberCount;
$this->groups[$i]->membersInChat = (string)$group->membersInChat;
$this->groups[$i]->membersInGame = (string)$group->membersInGame;
$this->groups[$i]->membersOnline = (string)$group->membersOnline;
$i++;
}
}
}
}
.
.
.
I already tried to using associative arrays, but didn't work; maybe with doing it all new. -_-
So, I can't set error_reporting(0) or ini_set at all.
I also used new stdClass() as a try. But I didn't get this running too.
You create an array.
$this->groups = array();
But in this array you donot create any object. You just use this array's elements (thoes are not initialized) as objects. You should add this line before your 132. row.
$this->groups[$i] = new Group();
Or something similar.
If you do not have Group class you should try
$this->groups[$i] = new stdClass();

Categories