PHP Class Happyr\LinkedIn\LinkedIn

When a new user arrives and want to authenticate here is whats happens: 1. You redirect him to whatever url getLoginUrl() returns. 2. The user logs in on www.linkedin.com and authorize your application. 3. The user returns to your site with a *code* in the the $_REQUEST. 4. You call isAuthenticated() or getAccessToken() 5. If we don't have an access token (only a *code*), getAccessToken() will call fetchNewAccessToken() 6. fetchNewAccessToken() gets the *code* from the $_REQUEST and calls getAccessTokenFromCode() 7. getAccessTokenFromCode() makes a request to www.linkedin.com and exchanges the *code* for an access token 8. When you have the access token you should store it in a database and/or query the API. 9. When you make a second request to the API we have the access token in memory, so we don't go through all these authentication steps again.
Author: Tobias Nyholm ([email protected])
Inheritance: implements Happyr\LinkedIn\LinkedInInterface
Show file Open project: happyr/linkedin-api-client Class Usage Examples

Protected Properties

Property Type Description
$accessToken Happyr\LinkedIn\AccessToken The OAuth access token received in exchange for a valid authorization code. null means the access token has yet to be determined.

Public Methods

Method Description
__construct ( string $appId, string $appSecret, string $format = 'json', string $responseDataType = 'array' ) Constructor.
api ( $method, $resource, array $options = [] )
clearStorage ( )
get ( string $resource, array $options = [] ) : mixed See docs for LinkedIn::api().
getAccessToken ( )
getError ( )
getLastResponse ( )
getLoginUrl ( $options = [] )
hasError ( )
isAuthenticated ( )
post ( string $resource, array $options = [] ) : mixed See docs for LinkedIn::api().
setAccessToken ( $accessToken )
setFormat ( $format )
setHttpClient ( Http\Client\HttpClient $client )
setHttpMessageFactory ( Http\Message\MessageFactory $factory )
setResponseDataType ( $responseDataType )
setStorage ( Happyr\LinkedIn\Storage\DataStorageInterface $storage )
setUrlGenerator ( Happyr\LinkedIn\Http\UrlGeneratorInterface $urlGenerator )

Protected Methods

Method Description
filterRequestOption ( array &$options ) : string Modify and filter the request options. Make sure we use the correct query parameters and headers.
getAuthenticator ( ) : Authenticator
getFormat ( ) : string Get the default format to use when sending requests.
getRequestManager ( ) : RequestManager
getResponseDataType ( ) : string Get the default data type to be returned as a response.
getUrlGenerator ( ) : Happyr\LinkedIn\Http\UrlGeneratorInterface

Method Details

__construct() public method

Constructor.
public __construct ( string $appId, string $appSecret, string $format = 'json', string $responseDataType = 'array' )
$appId string
$appSecret string
$format string 'json', 'xml'
$responseDataType string 'array', 'string', 'simple_xml' 'psr7', 'stream'

api() public method

public api ( $method, $resource, array $options = [] )
$options array

clearStorage() public method

public clearStorage ( )

filterRequestOption() protected method

Modify and filter the request options. Make sure we use the correct query parameters and headers.
protected filterRequestOption ( array &$options ) : string
$options array
return string the request format to use

get() public method

See docs for LinkedIn::api().
public get ( string $resource, array $options = [] ) : mixed
$resource string
$options array
return mixed

getAccessToken() public method

public getAccessToken ( )

getAuthenticator() protected method

protected getAuthenticator ( ) : Authenticator
return Authenticator

getError() public method

public getError ( )

getFormat() protected method

Get the default format to use when sending requests.
protected getFormat ( ) : string
return string

getLastResponse() public method

public getLastResponse ( )

getLoginUrl() public method

public getLoginUrl ( $options = [] )

getRequestManager() protected method

protected getRequestManager ( ) : RequestManager
return Happyr\LinkedIn\Http\RequestManager

getResponseDataType() protected method

Get the default data type to be returned as a response.
protected getResponseDataType ( ) : string
return string

getUrlGenerator() protected method

protected getUrlGenerator ( ) : Happyr\LinkedIn\Http\UrlGeneratorInterface
return Happyr\LinkedIn\Http\UrlGeneratorInterface

hasError() public method

public hasError ( )

isAuthenticated() public method

public isAuthenticated ( )

post() public method

See docs for LinkedIn::api().
public post ( string $resource, array $options = [] ) : mixed
$resource string
$options array
return mixed

setAccessToken() public method

public setAccessToken ( $accessToken )

setFormat() public method

public setFormat ( $format )

setHttpClient() public method

public setHttpClient ( Http\Client\HttpClient $client )
$client Http\Client\HttpClient

setHttpMessageFactory() public method

public setHttpMessageFactory ( Http\Message\MessageFactory $factory )
$factory Http\Message\MessageFactory

setResponseDataType() public method

public setResponseDataType ( $responseDataType )

setStorage() public method

public setStorage ( Happyr\LinkedIn\Storage\DataStorageInterface $storage )
$storage Happyr\LinkedIn\Storage\DataStorageInterface

setUrlGenerator() public method

public setUrlGenerator ( Happyr\LinkedIn\Http\UrlGeneratorInterface $urlGenerator )
$urlGenerator Happyr\LinkedIn\Http\UrlGeneratorInterface

Property Details

$accessToken protected property

The OAuth access token received in exchange for a valid authorization code. null means the access token has yet to be determined.
protected AccessToken,Happyr\LinkedIn $accessToken
return Happyr\LinkedIn\AccessToken