Linkedin:权限请求不起作用

时间:2012-09-22 06:07:24

标签: api zend-framework linkedin

当我尝试从linkedin请求其他权限时,除了基本的permisiions之外,我没有在对话框中获得任何权限列表。任何人都可以指出我的解决方案。我尝试了urlencoding权限,但仍然没有得到任何响应。这是我的代码:我点击'Signup with Linkedin'按钮调用此功能。

public function linkedinaccessAction()
{
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    $scope = 'r_basicprofile+r_emailaddress+r_network+r_contactinfo';

    $options = array(
                            'version' => '1.0',
                            'siteUrl' => 'http://localhost/project/development/',
                            'callbackUrl' => 'http://localhost/project/development/signup/linkedinaccess',
                            'requestTokenUrl' => 'https://api.linkedin.com/uas/oauth/requestToken?scope=' . $scope,
                            'userAuthorizationUrl' => 'https://api.linkedin.com/uas/oauth/authorize',
                            'accessTokenUrl' => 'https://api.linkedin.com/uas/oauth/accessToken',
                            'consumerKey' => 'myconsumerkey',
                            'consumerSecret' => 'myconsumersecret'
                        );

    $consumer = new Zend_Oauth_Consumer( $options );


    if (!isset($_SESSION ['LINKEDIN_ACCESS_TOKEN'])){
        if(! empty ( $_GET )){
            //consumer = new Zend_Oauth_Consumer( $options );
            $accessToken = $consumer->getAccessToken ( $_GET, unserialize ( $_SESSION ['LINKEDIN_REQUEST_TOKEN'] ) ); 
            echo $accessToken;
            $_SESSION ['LINKEDIN_ACCESS_TOKEN'] = serialize ( $accessToken );
        }else{
            $requestToken = $consumer->getRequestToken();
            $_SESSION ['LINKEDIN_REQUEST_TOKEN'] = serialize ( $requestToken );
            $consumer->redirect();
        }
    }else{
        $accessToken = unserialize ( $_SESSION ['LINKEDIN_ACCESS_TOKEN'] ); 

        // Use HTTP Client with built-in OAuth request handling
        $client = $accessToken->getHttpClient($options);

        // Set LinkedIn URI
        $client->setUri('https://api.linkedin.com/v1/people/~');
        // Set Method (GET, POST or PUT)
        $client->setMethod(Zend_Http_Client::GET);
        // Get Request Response
        $response = $client->request();

        // Get the XML containing User's Profile
        $content =  $response->getBody();
        print_r($content);
    }

}

谢谢。

1 个答案:

答案 0 :(得分:1)

经过严格的搜索,最终得到了Linkedin Post

的解决方案

需要请求linkedin权限作为getRequestToken Call的一部分:

$requestToken = $consumer->getRequestToken(array('scope' =>'r_emailaddress'));