Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linkedin OAuth and Zend retrieving Acces Token returns 'Error in HTTP request'

Answer + new question

I found out that the code below works just fine on a LIVE server. LinkedIN blocked all requests from localhost.

That established; Does anybody know how to test an application from localhost with LinkedIN OAuth? Because doing this on a live server sucks!

Old Question

I'm trying to connect with Zend_OAuth to LinkedIN. This code used to work, but now it returns an error in http request while I'm trying to retrieve an access token.

Tried checking the LinkedIN api, but the code still seems valid. Tried several scripts but all with the same result.

The config is setup in the preDispatch of my controller

$this->configLinkedin = array(
        'version' => '1.0',
        'siteUrl' =>  'http://'.$_SERVER['HTTP_HOST'].$this->view->baseUrl(false).'/news/index/connectlinkedin', 
        'callbackUrl' => 'http://'.$_SERVER['HTTP_HOST'].$this->view->baseUrl(false).'/news/index/connectlinkedin',
        'requestTokenUrl' => 'https://api.linkedin.com/uas/oauth/requestToken', 
        'userAuthorisationUrl' => 'https://api.linkedin.com/uas/oauth/authorize', 
        'accessTokenUrl' => 'https://api.linkedin.com/uas/oauth/accessToken',
        'consumerKey' => 'XXX',
        'consumerSecret' => 'XXX'
    );

And the code in the action to connect to linkedIN is

$this->consumer = new Zend_Oauth_Consumer($this->configLinkedin);

    if(!empty($_GET) && isset($_SESSION['LINKEDIN_REQUEST_TOKEN']))
    {
        $token = $this->consumer->getAccessToken($_GET, unserialize($_SESSION['LINKEDIN_REQUEST_TOKEN']));
        // Use HTTP Client with built-in OAuth request handling
        $client = $token->getHttpClient($this->configLinkedin);
        // Set LinkedIn URI
        $client->setUri('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url)');
        // Set Method (GET, POST or PUT)
        $client->setMethod(Zend_Http_Client::GET);
        // Get Request Response
        $response = $client->request();         
        $this->NewsService->TokenSocialMedia(
            $token,
            'linkedin',
            serialize($response->getBody())
        );
        $_SESSION['LINKEDIN_REQUEST_TOKEN'] = null;
        $this->_helper->flashMessenger(array('message' => $this->view->translate('The CMS is successfully connected to your linkedin account'), 'status' => 'success'));
        $this->_helper->redirector('settings#settingSocial', 'index');
    }
    else
    {
        $token = $this->consumer->getRequestToken();
        $_SESSION['LINKEDIN_REQUEST_TOKEN'] = serialize($token);
        $this->consumer->redirect();
    }

What am I missing or doing wrong? I use a similair setup for Twitter and that works fine.

UPDATE 20 September 211

I found out that this rule is returning the error:

 $token = $this->consumer->getRequestToken();

I'm still clueless why, and reading the linkedin api doesn't help a bit. Will keep you posted.

like image 347
Rick de Graaf Avatar asked Nov 04 '22 17:11

Rick de Graaf


1 Answers

I got similar problem and after adding openssl extension it was solved

try adding to php.ini this line:

extension=php_openssl.dll
like image 107
Szymon Wygnański Avatar answered Nov 09 '22 12:11

Szymon Wygnański