Jump to content

Kesaven

Level 1
  • Posts

    0
  • Joined

  • Last visited

About Kesaven

Kesaven's Achievements

0

Reputation

  1. Hello Phils

    I am trying to integrate evernote in one of my websites using PHP SDK.

    Initially my requirement was simple:

    My boss has a premium account and i created a developer token and manages to get notes for a particular search string. it works a treat.

    However, i now need to add more accounts, so i created the tokens and tried to access the same way, but it does not work.

    This time the accounts are not premium.

     

    My code here:

    require_once '../libs/evernote/src/autoload.php';
    require_once('../libs/mysql.class.php');
    require_once('../libs/debug.php');
    require_once('../libs/functions.php');
    
    session_start();
    
    $gMysql = new MySQL_Class(array("host"=>"localhost","user"=>"horscote","password"=>"feO@6i77","dbname"=>"horscote"));
    $gMysql->connect();
     
    $siren = $_POST['id'];
     
    //if logged user - saved as viewed
    $sqlViewed = 'SELECT evernoteSync FROM company WHERE SIREN='.$siren;
    $isSync = $gMysql->queryValue($sqlViewed);
    $gMysql->close();
    
    if($isSync==1)
    {
        $gMysql->connect();
        //get all admin evernotes
        $evernotes = $gMysql->queryList('SELECT * FROM evernote_users e inner join users u on u.id=e.userid WHERE evernote=1 ORDER BY e.ID');
    
        
        $maintable = '';
        foreach($evernotes as $evernote)
        {
            //var_dump($evernote);
            
            $token = $evernote['token'];
    
            $sandbox = false;
            $china   = false;
    
            $client = new \Evernote\Client($token, $sandbox, null, null, $china);
        
            $search = new \Evernote\Model\Search($siren);
        
            $notebook = new \Evernote\Model\Notebook();
        
            //$notebook->guid = $evernote['notebook_guid'];
    
            //$scope = \Evernote\Client::SEARCH_SCOPE_ALL;
    
            //$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
    
            //var_dump($notebook);
            $maxResult = 5;
    
            $results = $client->findNotesWithSearch($search, $notebook, $scope, $order, $maxResult);
    
            //var_dump($results);
    
            $table = '<div class="panel-group" id="accordionEvernote" role="tablist" aria-multiselectable="true" style="margin-top:10px">';
            $i=0;
            foreach ($results as $result) {
                $noteGuid    = $result->guid;
                $note = $client->getNote($noteGuid);
    
                $in = '';
                if($i==0)
                {
                    $in = ' in';
                    $plusMinus = '<i class="more-less fa fa-chevron-right"></i>';
                }
                else
                {
                    $plusMinus = '<i class="more-less fa fa-chevron-right"></i>';
                }
            
                $advancedClient = new \Evernote\AdvancedClient($token, $sandbox);
                $noteStore = $advancedClient->getNoteStore();
                $userStore = $advancedClient->getUserStore();
                $userInfo = $userStore->getPublicUserInfo($evernote['username']);
     
                $completeNote = $noteStore->getNote($token,$noteGuid,TRUE,TRUE,TRUE,TRUE);
                $resources = $completeNote->resources;
                $sResources = '';
                foreach($resources as $res)
                {
                    $resource = $noteStore->getResource($token, $res->guid, true, true, true, true);        
                    $fileContent = $res->data->body;  
                    $fileType = $res->mime;  
                    $fileName = $res->attributes->filename;
                            
                    $resGuid = $res->guid; // example GUID
                    $resUrl = $userInfo->webApiUrlPrefix . 'res/' . $resGuid;
     
                    $attribute = $noteStore->getResourceAttributes($token, $res->guid);  
     
                    $fileName = $attribute->fileName;
                    $sResources .= '
                    <div class="col-xs-10 col-sm-4 col-md-2">
                  <div class="thumbnail" style="text-align:center">
                    <i class="fa fa-file-text" aria-hidden="true" style="font-size:40px;color:#F05F40"></i>
                      <div class="caption">
                        <a tatget="_blank" href="'.$resUrl.'" style="font-size:10px">'.$fileName.'</a>
                    </div>
                  </div>
                </div>';
                }
                    
                $tags = $noteStore->getNoteTagNames($token,$noteGuid);
    
                $created = date('d/m/Y',$completeNote->created/1000); 
                $updated = date('d/m/Y',$completeNote->updated/1000); 
    
                $hashTags = '';        
                foreach($tags as $tag)
                {
                    $hashTags .='<span class="label label-primary" style="margin-right:5px"> <i class="fa fa-tag" aria-hidden="true"></i> '.$tag.'</span>';
                }
    
                $table .='<div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading'.$note->guid.'">
                        <h4 class="panel-title" style="font-size:12px">
                            <a role="button" data-toggle="collapse" data-parent="#accordionEvernote" href="#collapse'.$note->guid.'" aria-expanded="true" aria-controls="collapse'.$note->guid.'">
                            
                                '.$plusMinus.'
                                '.$note->title.' - Crée le '.$created.' par '.$evernote['firstName'].' - Modifié le '.$updated.'</i>
                            </a>
                        </h4>
                    </div>
                    <div id="collapse'.$note->guid.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading'.$note->guid.'">
                        <div class="panel-body">
                              <div id="ntD'.$note->guid.'">  
                              <div style="margin-bottom:10px">'.$hashTags.'</div>
                              <div style="margin-bottom:10px" id="resources" class="row">'.$sResources.'</div>
                              '.$note->content.'
                              </div>
                        </div>
                    </div>
                </div>';
            
                
                $i++;
            }
            $maintable .=$table;
        }
    
        $gMysql->close();
    
        if(isset($noteGuid) && !empty($noteGuid))
        {
            
            echo '<div style="text-align:justify">'.$maintable.'</div>';
        }
        else
        {
            $table = 'Aucune note trouvée pour cette société.';
            echo $table;
        
        }
    }
    else
    {
        $table = '<div style="text-align:center"><button class="btn btn-success btn-lg" onclick="sync('.$siren.')"> Syncroniser</button></div>';
        echo $table;
    }

     

     

    Thanks

     

    1. phils

      phils

      Hi Kesaven,

      I"m afraid I'm not familiar with PHP so will be difficult to help.  Try contacting @Laurent Sarrazin - he's the Evernote PHP guru.

×
×
  • Create New...