zend-framework – Linkedin OAuth和Zend检索Acces Token返回’HTTP请求中的错误’

回答新问题

我发现下面的代码在LIVE服务器上工作得很好. LinkedIN阻止了来自localhost的所有请求.

那确立了;有人知道如何使用LinkedIN OAuth从localhost测试应用程序吗?因为在实时服务器上这样做很糟糕!

老问题

我正在尝试将Zend_OAuth连接到LinkedIN.此代码曾经工作,但现在它在我尝试检索访问令牌时在http请求中返回错误.

尝试检查LinkedIN api,但代码似乎仍然有效.尝试了几个脚本但都具有相同的结果.

配置是在我的控制器的preDispatch中设置的

$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'
    );

并且连接到linkedIN的操作中的代码是

$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();
    }

我错过了什么或做错了什么?我使用Twitter的similair设置,并且工作正常.

更新于9月20日211

我发现此规则返回错误:

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

我仍然无能为力,阅读linkedin api并没有多大帮助.将及时向大家发布.

最佳答案 我遇到了类似的问题,在添加openssl扩展后它就解决了

尝试添加到php.ini这一行:

extension=php_openssl.dll
点赞