CakePHP-Copula / Linkedin

LinkedIn API support for Cakephp.
16 stars 9 forks source link

Example on how to specify optional parameters for people search API #4

Closed andyjn closed 12 years ago

andyjn commented 12 years ago

Hi,

I have the plugin installed and I can return my profile and also can get 10 results back from the People Search API. I can see there is a list of optional parameters for People Search but i cant figure out how to specify these in the find() command.

Could you provide a quick example on how to search for firstName, lastName and company and return count of 500 results?

Thanks!

ProLoser commented 12 years ago

So LinkedIn was the only API I encountered that lets you specify what fields you want to return, which sort of threw a wrench into how I normally do stuff in other APIs.

Bottom line is simply pass those options as conditions:

$data = $this->find('all', array(
            'path' => 'people-search',
            'conditions' => array(
                        'count' => 500,
                        'firstName' => 'bob',
                        'lastName' => 'dillan',
                        'company' => 'columbia records club',
            ),
            'fields' => array(
                'first-name', 'last-name',
                'positions' => array('title', 'company'), 
            ),
        ));

The fields key is optional and specifies what data you want returned. Refer here for a list

I will add the demo to the docs, if you want/need more endpoints it's easy to add them yourself or just tell me what sections you want and I can add them for you. I also need to tweak the code because you should not be using the 'path' key but it appears I did not add support for a 'section' or 'resource' key. Specifying the path means I expect people to know exactly what endpoint to use, however part of the design of this plugin is that you only have to know what section to use and the plugin will figure out the url/endpoint for you.

andyjn commented 12 years ago

Hi.

Thanks for the prompt response really appreciate it!

Andy

Dean Sofer reply@reply.github.com wrote:

So LinkedIn was the only API I encountered that lets you specify what fields you want to return, which sort of threw a wrench into how I normally do stuff in other APIs.

Bottom line is simply pass those options as conditions:

$data = $this->find('all', array(
           'path' => 'people-search',
           'conditions' => array(
                       'count' => 500,
                       'firstName' => 'bob',
                       'lastName' => 'dillan',
                       'company' => 'columbia records club',
           ),
           'fields' => array(
               'first-name', 'last-name',
               'positions' => array('title', 'company'), 
           ),
       ));

The fields key is optional and specifies what data you want returned. Refer here for a list

I will add the demo to the docs, if you want/need more endpoints it's easy to add them yourself or just tell me what sections you want and I can add them for you. I also need to tweak the code because you should not be using the 'path' key but it appears I did not add support for a 'section' or 'resource' key. Specifying the path means I expect people to know exactly what endpoint to use, however part of the design of this plugin is that you only have to know what section to use and the plugin will figure out the url/endpoint for you.


Reply to this email directly or view it on GitHub: https://github.com/ProLoser/CakePHP-LinkedIn/issues/4#issuecomment-6688328

andyjn commented 12 years ago

Hi,

Thanks for you assistance so far. I thought i had tried what you suggested and turns out i had already without success. The debug output for the API request built from this code:

$this->setDataSource('linkedin');
        $data = $this->find('all', array(
            'path' => 'people-search',
            'conditions' => array(
                        'count' => 500,
                        'firstName' => 'bob',
                        'lastName' => 'dillan',
                        'company' => 'columbia records club',
            ),
             'fields' => array(
                 'first-name', 'last-name', 
                 'positions' => array('title', 'company'), 
             ),
        ));

is show below:

---REQUEST--- GET /v1/people-search:(first-name,last-name,positions:(title,company)) HTTP/1.1 Host: api.linkedin.com Connection: close User-Agent: CakePHP x-li-format: json Authorization: OAuth oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="snip",oauth_token="snip",oauth_nonce="snip",oauth_timestamp="1341158482",oauth_signature="snip" 

---RESPONSE--- HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 x-li-request-id: D6IXXXGX Date: Sun, 01 Jul 2012 16:01:22 GMT Vary: * x-li-format: json Content-Type: application/json;charset=UTF-8 Content-Length: 166 Connection: close { "errorCode": 0, "message": "Unknown field {first-name} in resource {PeopleSearch}", "requestId": "D6IXXX8GX", "status": 400, "timestamp": 1341158483130 } 

I have tried changing first-name to firstName without success. Also, the "count" = 500 condition specified in the find() call does not appear in the Request that I can see?

From the People Search API documentation I would expect the GET to be something like:

GET /v1/people-search:(people(first-name,last-name,positions:(title,company)))?count=500

Thanks

Andy

ProLoser commented 12 years ago

Ya sorry this is because we're not using the mapping feature. If you use 'section' instead of path the mapping feature will be engaged, however if you choose to stick to using 'path' then all of the conditions will be passed as query parameters now.

Update the ApisSource to get the changes. Unfortunately I haven't had time to test these changes, so let me know if you encounter some bug or typo.

andyjn commented 12 years ago

Hi,

Thanks for all your help so far. When using

$data = $this->find('all', array(
            'path' => 'people-search',
            'conditions' => array(
                        'count' => 500,
                         //'first-name' => 'bob',
                         //'last-name' => 'dillan',
                       'company-name' => 'Barclays'

            ),
              'fields' => array(
                  'people' => array('first-name', 'last-name', 'positions' => array('is-current', 'title', 'company' => array('name')) )

              ),
        ));
---REQUEST--- GET /v1/people-search:(people:(first-name,last-name,positions:(is-current,title,company:(name)))) HTTP/1.1 

I can specify the "fields" array and get back the fields i need, but the conditions are not being passed through.

When i use

$data = $this->find('all', array(
            'section' => 'people-search',
            'conditions' => array(
                        'count' => 500,
                         //'first-name' => 'bob',
                         //'last-name' => 'dillan',
                       'company-name' => 'Barclays'

            ),
              'fields' => array(
                  'people' => array('first-name', 'last-name', 'positions' => array('is-current', 'title', 'company' => array('name')) )

              ),
        ));
---REQUEST--- GET /v1/people-search?count=500&company-name=Barclays HTTP/1.1 

then the conditions are set, but the fields array isnt added to the API GET request. I have tried but failed to modify the plugin to tack the query parameters after the field selector. I think im doing this after the request has been signed so its not being authorized. Am i using the find command incorrectly or is this a bug?

I would expect the GET Request URI to be something like:

GET https://api.linkedin.com/v1/people-search:(people:(first-name,last-name,positions:(is-current,title,company:(name))))?company-name=Barclays&last-name=Diamond

Many Thanks

Andy