Jump to content

Welcome! You're currently a Guest.

If you'd like to join in the Discussion, or access additional features in our forums, please sign in with your Evernote Account here. Have an Evernote Account but forgot your password? Reset it! Don't have an account yet? Create One! You'll need to set your Display Name before your first post.

Photo

will findNotes() interrupt the following datas?


  • Please log in to reply
9 replies to this topic

#1 Lil Dre

Lil Dre

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 71 posts

Posted 12 August 2012 - 03:20 PM

hello!! everyone. I found findNotes() will interrupt the following datas, when some remainings come.

it's my test codes:


$listnote = $noteStore->listNotebooks($_SESSION['accessToken']);

$notebookone = $listnote;
$notebookguid = $notebookone->guid;

$filter = new NoteFilter();
$filter->notebookGuid = $notebookguid;
$offset = 0;

for($i = 0; $i < 101; $i++){
$notesList = $noteStore->findNotes($_SESSION['accessToken'], $filter, $offset, 1000);
$remain = ($notesList->totalNotes) - (($notesList->startIndex) + (count($notesList->notes)));
echo 'test' . '<br>';
}


it can not print one hundred with test.

it just stuck in about 20 to 25. and then interrupt the following datas

I mean can not print other datas after these codes. like if findNotes() produce some remainings, it will use "exit()" to break off all of data after this.

even I change my code to:

$listnote = $noteStore->listNotebooks($_SESSION['accessToken']);

$notebookone = $listnote;
$notebookguid = $notebookone->guid;

$filter = new NoteFilter();
$filter->notebookGuid = $notebookguid;
$offset = 0;
do{
for($i = 0; $i < 101; $i++){
$notesList = $noteStore->findNotes($_SESSION['accessToken'], $filter, $offset, 1000);
$remain = ($notesList->totalNotes) - (($notesList->startIndex) + (count($notesList->notes)));
echo 'test' . '<br>';
}
while($remain > 0);


it still have the same situation.

because of my code, $remain? Is it wrong? I test it before. its value is 0 all the time.

Does anybody know have the same situation like me?

#2 Lil Dre

Lil Dre

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 71 posts

Posted 13 August 2012 - 10:16 AM

nobody knows?

#3 Garrett

Garrett

  • Title: Member
  • Group: Evernote Employee
  • 41 posts

Posted 13 August 2012 - 08:19 PM

Hi, Lil Dre. Because each call to findNotes() sends a request to Evernote's server, it is not advised to call it 101 times in a row. Additionally, because "$offset" is always 0, each call in your code will return the same list of notes. Try adjusting the offset in your loop to get all the notes matching the filter:
do {
  $notesList = $noteStore->findNotes($_SESSION['accessToken'], $filter, $offset, 20);
  $offset = $notesList->startIndex + count($notesList->notes);
  $remain = $notesList->totalNotes - $offset;
  foreach ($notesList->notes as $note) {
    print $note->title . "<br />";
  }
} while($remain>0);


#4 Lil Dre

Lil Dre

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 71 posts

Posted 14 August 2012 - 12:49 AM

Hi Garrett. thanks for help, but why I just can print 30 notes? if I have 31 notes, it just print 30 notes totally.


$listnote = $noteStore->listNotebooks($_SESSION['accessToken']);

$notebookone = $listnote;
$notebookguid = $notebookone->guid;

$filter = new NoteFilter();
$filter->notebookGuid = $notebookguid;
$offset = 0;
$result = array();

do{
$notesList = $noteStore->findNotes($_SESSION['accessToken'], $filter, $offset, 100);
$offset = $notesList->startIndex + count($notesList->notes);
$remain = $notesList->totalNotes - $offset;

for($i = 0; $i < count($notesList->notes); $i++){
$note = $notesList->notes[$i];
$fullNote = $noteStore->getNote($_SESSION['accessToken'], $note->guid, true, false, false, false);
$date = date('Y-m-d H:i:s',$fullNote->created/1000);
if($date >= $_SESSION['t_date'] && $date <= $_SESSION['t_date2']){
echo $fullNote->title . '<br>';
}
}
}while($remain > 0);


#5 Garrett

Garrett

  • Title: Member
  • Group: Evernote Employee
  • 41 posts

Posted 14 August 2012 - 07:39 AM

I was able to print out more than 30 notes using your code, but depending on the values of "t_date" and "t_date2", there might simply be fewer than 31 matches in your notebook. Instead of finding all the user's notes and then filtering out dates that don't match, I would recommend using the NoteFilter to do that work for you. For example, to find notes created between August 7, 2012 and August 9, 2012:

$filter = new NoteFilter();
$filter->notebookGuid = $notebookguid;
$filter->words = "created:20120807 -created:20120809";
$offset = 0;

do {
  $notesList = $noteStore->findNotes($_SESSION['accessToken'], $filter, $offset, 20);
  $offset = $notesList->startIndex + count($notesList->notes);
  $remain = $notesList->totalNotes - $offset;
  foreach ($notesList->notes as $note) {
    print $note->title . "<br />";
  }
} while($remain>0);

More details about the search grammar are available at http://dev.evernote....rch_grammar.php

#6 Lil Dre

Lil Dre

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 71 posts

Posted 15 August 2012 - 08:42 AM

Hi Garrett! thank you.

but why I could not just print note's content? like:

foreach ($notesList->notes as $note) {
print $note->content . "<br />";
}

because I found getNote() will note print out more than 30 notes, I don't wanna use that.

But I use "$note->content" to print out note's content, it not work.

you know, if I use getNote() like:

foreach ($notesList->notes as $note) {
$fullNote = $noteStore->getNote($_SESSION['accessToken'], $note->guid, true, false, false, false);
$fullNote->content;
}

it just couldn't print out more than 30, sometimes even print out none of notes.

for me, only this code can print out 50 notes totally. like:


$listnote = $noteStore->listNotebooks($_SESSION['accessToken']);

$notebookone = $listnote;
$notebookguid = $notebookone->guid;

$filter = new NoteFilter();
$filter->notebookGuid = $notebookguid;
$offset = 0;

foreach ($notesList->notes as $note) {
$note->content;
}


#7 Garrett

Garrett

  • Title: Member
  • Group: Evernote Employee
  • 41 posts

Posted 15 August 2012 - 08:31 PM

but why I could not just print note's content?


To keep service fast and responsive, we do not send full note content when you call findNotes()... each note could be several megabytes in size! Instead we send a list of notes with associated metadata, and you can access an individual note's content by calling getNote() with the appropriate GUID.

you know, if I use getNote()... it just couldn't print out more than 30, sometimes even print out none of notes.


Most PHP configurations have execution time limits in place... if your script takes more than a few seconds to run, it will be stopped by your server. Because each call to getNote() sends a request to Evernote's server and waits on a response, calling this function more than a few times on a page could result in your application's execution being cut off.

Some users have thousands of (potentially large) notes, so you should not expect to be able to print all the notes from a user's account onto a single page.

#8 Lil Dre

Lil Dre

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 71 posts

Posted 15 August 2012 - 11:38 PM

okay Garrett, I got it.

so I need to add "ini_set('max_execution_time', 300); //300 seconds = 5 minutes" to top of php

#9 Garrett

Garrett

  • Title: Member
  • Group: Evernote Employee
  • 41 posts

Posted 16 August 2012 - 01:04 AM

The simplest solution is simply to break the results into multiple pages with fewer notes per page. If all the notes must appear together, you could use AJAX calls to combine multiple server requests into a single page. Finally, if you have access to your server configuration files, you could increase timeout values to allow your script to run longer... though this will probably not provide the best user experience.

#10 Lil Dre

Lil Dre

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 71 posts

Posted 16 August 2012 - 01:38 AM

thx man, that looks like a big work. I'll try.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Clip to Evernote