3

現在、LinkedIn トークンの取得に問題があります。

私は現在、authentication を通過するために開発者のドキュメントに従っています。

このサンプルをベースコードとしても使用しています

ただし、認証コードを取得する認証プロセスを通過した後、ユーザーのトークンを取得するプロセスが失敗し、Bad Request Error (400) が表示されます。

サンプルページから変更されたコードは次のとおりです (注:コメント部分は、cURL に移動する前に行った以前の試みです)

 public function getAccessToken() {
        $params = array('grant_type' => 'authorization_code',
            'client_id' => API_KEY,
            'client_secret' => API_SECRET,
            'code' => $_GET['code'],
            'redirect_uri' => REDIRECT_URI.'/linkedin/auth',
        );


        // Access Token request
        $url = urldecode('https://www.linkedin.com/uas/oauth2/accessToken?'.http_build_query($params));
        //header("Content-length: ".strlen($url));
        // Tell streams to make a POST request


        echo $url;

        /*$context = stream_context_create(
            array('http' =>
            array('method' => 'POST',
            )
            )
        );*/

        /*$context  = stream_context_create(
                        array('http' =>
                            array('method'  => 'POST',
                                  'header'  => 'Content-type: application/x-www-form-urlencoded',
                                  'content' => http_build_query($params))
                        )
                    );

        // Retrieve access token information
        $response = file_get_contents($url, FALSE, $context);*/


        $ch = curl_init();

        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST,1);
        $response = curl_exec($ch);

        curl_close($ch);

        $token = json_decode($response);

        echo json_decode($response);

        // Store access token and expiration time
        $_SESSION['access_token'] = $token->access_token; // guard this!
        $_SESSION['expires_in']   = $token->expires_in; // relative time (in seconds)
        $_SESSION['expires_at']   = time() + $_SESSION['expires_in']; // absolute time

        return true;
}

言及するのを忘れていましたが、この部分は、ブラウザに手動で挿入すると有効なユーザー トークンを生成するecho $url;URL を出力します。

4

1 に答える 1

3

リクエストが機能するためには、GET代わりに で送信する必要がありますPOST

次の行を削除します。

curl_setopt($ch,CURLOPT_POST,1);
于 2013-05-06T18:50:43.387 に答える