繁体   English   中英

当我获得LinkedIn的访问令牌时得到401

[英]got a 401 when I get access token for LinkedIn

$ oauth-> getAccessToken()导致无效的auth / bad请求(获得401,预期的HTTP / 1.1 20X或重定向)。

我如何查看请求标头以找出到底是什么问题?

    $oauth = new OAuth(CONSUMER_KEY, CONSUMER_SECRET);

    $oauth->disableSSLChecks();
    $request_token_response = $oauth->getRequestToken('https://api.linkedin.com/uas/oauth/requestToken');

    if($request_token_response === FALSE) {
            throw new Exception("Failed fetching request token, response was: " . $oauth->getLastResponse());
    } else {
        $request_token = $request_token_response;
        var_dump($request_token);

        if (!isset($_GET['oauth_verifier'])) {
            $this->redirect("https://api.linkedin.com/uas/oauth/authorize?oauth_token=" . $request_token['oauth_token']);
        } else {
            $oauth_verifier = $_GET['oauth_verifier'];
            $oauth->setToken($request_token['oauth_token'], $request_token['oauth_token_secret']);

            $access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken';
            $access_token_response = $oauth->getAccessToken($access_token_url, "", $oauth_verifier);

            if($access_token_response === FALSE) {
                    throw new Exception("Failed fetching request token, response was: " . $oauth->getLastResponse());
            } else {
                $access_token = $access_token_response;

                $params = array();
                $headers = array();
                $method = OAUTH_HTTP_METHOD_GET;

                // Specify LinkedIn API endpoint to retrieve your own profile
                $url = "http://api.linkedin.com/v1/people/~";

                // By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
                // $url = "http://api.linkedin.com/v1/people/~?format=json";

                // Make call to LinkedIn to retrieve your own profile
                $oauth->fetch($url, $params, $method, $headers);

                echo $oauth->getLastResponse();
            }
        }

    }       
}

oauth_verifier仅验证从中获取请求的请求令牌。 我需要在会话中存储原始的request_token,而不是在回调中获取新的request_token。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM